Got a -0.00 payment balance in patient visit

anonymous wrote on Thursday, November 29, 2012:

Please some one tell me the reason for this. some times I got -0.00 as balance in patient ledger. Client is asking for reason. I cant able to explain. But fixed the issue. It is disappointing very much.

Fixed the issue after seeing this:

http://stackoverflow.com/questions/6925358/sprintf-adds-minus-sign-to-zero-after-rounding?rq=1

Thanks in advance.

sunsetsystems wrote on Friday, November 30, 2012:

Yes I guess it results from rounding a very small negative number. Shouldn’t hurt anything.

Rod
www.sunsetsystems.com

sriniemr wrote on Saturday, December 01, 2012:

Rod,
        Thanks for your reply,Could you please suggest  me,How we can avoid this Negative zero,we really need this to avoid??

Thanks

sunsetsystems wrote on Saturday, December 01, 2012:

Not sure what you mean by “patient ledger”.  Please indicate exactly what you do to select the report in question, and where in that report the -0.00 appears, and I can surely point you in the right direction.

Rod
www.sunsetsystems.com

anonymous wrote on Sunday, December 02, 2012:

Hi Rod,

This is also something I have experienced on our install. I just reproduced the issue with patient “John Doe” on the demo. The only place I’m seeing the -0 is in the billing view of the encounters frame. The -0 does not appear on the billing ledger (statement) or billing widget above patient demographics.

I haven’t looked into the code, but it doesn’t seem there is a database entry for this value. Is this balance calculated on the fly from (Charge - Adjustment - Payment = Balance)? If so, perhaps the above fix can be utilized in /interface/patient_file/history/encounters.php

sunsetsystems wrote on Monday, December 03, 2012:

Sounds like you’re on the right track.  It appears that code uses function oeFormatMoney() from library/formatting.inc.php, so try the fix there.

Rod
www.sunsetsystems.com

sriniemr wrote on Wednesday, December 05, 2012:

Rod,
         Got a solution 0.00 instead of -0.00 while i were use round(),But i need to make sure is this is right fix.Also  is there any chance to get -0.00 in any cases.please let me know.

$balance = sprintf("%.2f", $row + $row - $row - $row);

Thanks,

kevmccor wrote on Wednesday, December 05, 2012:

This is an example from php documentation:

<?php
$money1 = 68.75;
$money2 = 54.35;
$money = $money1 + $money2;
// echo $money will output "123.1";
$formatted = sprintf("%01.2f", $money);
// echo $formatted will output "123.10"
?>

I think two lines may be necessary, round sum to 2 places, then format (why are copays added?):

$b1 = round($row['charges'] + $row['copays'] - $row['payments'] - $row['adjustments', 2);
$balance =  sprintf("%01.2f", $b1);
 --or --
$balance =  oeFormatMoney($b1);

I think if any PHP float is negative then the negative sign appears.  This can happen because of computer arithmetic where string or integer formats are converted or other reasons.  It appears the rounding will fix it because the negative values are in the higher decimal places.  To be certain, you should create a set of test cases.

sunsetsystems wrote on Wednesday, December 05, 2012:

My suggestion was to modify the oeFormatMoney() function in library/formatting.inc.php.  This is what takes a monetary amount which might be floating point and converts it to display format.  For example after the “function” line try adding this:

$amount = round($amount, $GLOBALS) + 0;

That’s just a suggestion based on the link in your first post.  If it doesn’t work, try some other tweak in that same location.  Doing it there will also take care of the same problem in other areas.

Rod
www.sunsetsystems.com