in reply to Issue getting value from text file and keep decimal
The issue is that you go back and forth between number and string representation. In $main_balance = $main_balance - $debit; the minus is a numeric operation, so perl translates your string into numbers, where the number of displayed digits is not memorized. Your format function turns it back into a string, but the formatting already has been lost.
I think your best option is Number::Format, which will output the expected format wheter the input is already a number, or a string representation (if the string doesn't already includes thousands separator, "900,000" will be interpreted as the number 900).
Also the sigil @ is used to fetch several elements, and $ a single one. So even if you are using a single element from an array, $ has to be used (see perldata). The second element of the array @fields should therefore be $fields[1] instead. Perl will actually complain about this if warnings are activated (which they should be).
Edit: turned $fields1 into $fields[1], thanks AnomalousMonk
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Issue getting value from text file and keep decimal
by jason.jackal (Novice) on Jun 26, 2017 at 15:09 UTC | |
by Eily (Monsignor) on Jun 26, 2017 at 15:17 UTC | |
by jason.jackal (Novice) on Jun 26, 2017 at 15:34 UTC | |
by Eily (Monsignor) on Jun 26, 2017 at 15:56 UTC |