http://qs1969.pair.com?node_id=1193573


in reply to Issue getting value from text file and keep decimal

UPDATE2: You were close. You want to set the decimal places to 2 values before you add commas. See also Number::Format. This works for me:
$format_main_balance = format_value(sprintf("%.2f",$main_balance +));

UPDATE1: I just read-read your question, and I now see the decimal dropped for 900,000.

OLD... IGNORE: When I run your code, it seems to keep decimals. Here is the output I get:

DATE DESCRIPTION DEBIT CRED +IT BALANCE ====================================================================== +================== 2017-05-01 starting balance to track character cou~ 900, +000.00 900,000 2017-05-01 phone bill dsfsdfsfdsfsfsfsdfsfsfsfsfdf~ 300,000.00 + 600,000 2017-05-03 Water 100,000.34 + 499,999.66 2017-05-05 Electric Bill 900.21 + 499,099.45 2017-06-03 debit 45678901dfsf2345678901234567890dd~ 30.32 + 499,069.13 2017-06-03 12345678901234567890123456789034 + 30.98 499,100.11 2017-06-03 credit 89012345678901234567890345678901~ + 30.98 499,131.09 2017-06-03 credit dfdfd012345678901234567890345678~ + 30.98 499,162.07 2017-06-08 Food 23.00 + 499,139.07 2017-06-12 Cash 20.00 + 499,119.07

Do you get a different output? If so, post exactly what you get. I'm using Perl version 5.16.3.

Basic debugging checklist

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 14:46 UTC
    Thank you for your reply. Notice how the first like is dropping the decimal. 900,000.00 credit in but only showing 900,000 as the balance field. Thank you
      You may have missed my second update. It now works for me as expected when I use this code in 2 places:
      $format_main_balance = format_value(sprintf("%.2f",$main_balance +));
      DATE DESCRIPTION DEBIT CRED +IT BALANCE ====================================================================== +================== 2017-05-01 starting balance to track character cou~ 900, +000.00 900,000.00 2017-05-01 phone bill dsfsdfsfdsfsfsfsdfsfsfsfsfdf~ 300,000.00 + 600,000.00 2017-05-03 Water 100,000.34 + 499,999.66 2017-05-05 Electric Bill 900.21 + 499,099.45 2017-06-03 debit 45678901dfsf2345678901234567890dd~ 30.32 + 499,069.13 2017-06-03 12345678901234567890123456789034 + 30.98 499,100.11 2017-06-03 credit 89012345678901234567890345678901~ + 30.98 499,131.09 2017-06-03 credit dfdfd012345678901234567890345678~ + 30.98 499,162.07 2017-06-08 Food 23.00 + 499,139.07 2017-06-12 Cash 20.00 + 499,119.07
        Hi, Yes I did miss your other post - still trying to learn the message board. It works now thank you so much. I knew it was super easy and I was near, but needed the extra help. Why was the case that I needed to format the code the way you did? I am a little confused.
Re^2: Issue getting value from text file and keep decimal
by jason.jackal (Novice) on Jun 27, 2017 at 13:33 UTC
    Hi, Let me ask you this. I am not always able to install applications on machines I use, and due to the latter I will be looking at methods to port my perl script to an EXE file. If I use a library/module from CPAN will that library or module compile to EXE on with my script so I just need a few files? Thank you - never used CPAN before. Much appreciated. Thank you JJ