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
In reply to Re: Issue getting value from text file and keep decimal
by Eily
in thread Issue getting value from text file and keep decimal
by jason.jackal
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |