smartyrounding

round in Smarty shows wrong result


In my Smarty 3 template I have this code:

{$a=8.34}
{$b=8.33}
{$a-$b|round:2}

Expected result is: 0.01

But I receive this: 0.0099999999999998

Does anybody know how to fix this?


Solution

  • Smarty2 applied the modifier to the result of the complete expression.

    Smarty3 does it just on the direct prepending value.

    So in Smarty3 you have to use brackets:

    {($a-$b)|round:2} 
    

    That should solve it.