I'm almost embarassed to post this. Learning Perl from scratch, I'm happy with what I thought were going to be the difficult bits - I have a web-based system that is happily loading orders to and from a database using the appropriate modules. So far, so good.
Until I tried putting in an order which pushed the total line value stored over 1000. At which point, totalling up the line values to produce a grand total, I realised that all I was adding was 1 for 1000, 2 for 2000 etc. Numbers less than a thousand are fine.
OK, I know a bit about why it is failing, I think (although someone correct me if I am wrong). Perl is storing the numbers as scalars but with a thousands separator as a comma. Any time I try and use that, it thinks I am trying to read a list into a scalar and just grabs the first item, i.e. the number before the comma.
So if I have:
$mynum=2000.99;
$totalline = sprintf("%11.2f\n", $mynum);
all I get in $totalline is "2\n".
I'm using ActiveState Perl 5 on NT.
I have to be missing something here (apart from a Linux machine - but I don't think that would solve THIS problem) - someone embarass me by telling me what I am doing wrong?
Thanks
Martin GK
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.