Topic: Rounding error in includes/ui/ui_view.inc -> price_in_words()
Hello,
Calling price_in_words() on the amount 1960.58 with user_price_dec set to 2 produces the string ''One Thousand Nine Hundred and Sixty and 57/100'' <-- Note ''57/100'' which should be ''58/100''.
Also, the amount 16418.29 produces ''Sixteen Thousand Four Hundred and Eighteen and 28/100''. Again, note ''28/100'' instead of ''29/100''.
The following patch to ui_view.inc seems to fix the problem for me, but I'm not sure if it's the best fix. Can you think of a better one?
--- ui_view-orig.inc 2012-02-07 13:24:33.398225655 -0500
+++ ui_view.inc 2012-02-07 13:24:36.218220917 -0500
@@ -774,7 +774,7 @@
if ($dec > 0)
{
$divisor = pow(10, $dec);
- $frac = round2($amount - floor($amount), $dec) * $divisor;
+ $frac = (int) round2(($amount - floor($amount)) * $divisor, $dec);
$frac = sprintf("%0{$dec}d", $frac);
$and = _("and");
$frac = " $and $frac/$divisor";