Re: [SMARTY-DEV] string_format rounding error..
| From: | messju mohr | Date: | Tue, 23 Jan 2007 11:41:21 +0000 |
| Subject: | Re: [SMARTY-DEV] string_format rounding error.. | ||
| Groups: | php.smarty.dev | ||
| Request: | Send a blank email to php-smarty-dev+get-2937@lists.php.net to get a copy of this message | ||
In-Reply-To: <45B5F225.30600@sbsquared.com>
On Tue, Jan 23, 2007 at 11:31:49AM +0000, Jonathan Lozinski wrote:
> Smarty Version: 2.6.0 (on debian stable)
> There is a rounding problme with .xx5 on smarty's string_format:"%.2f"
> modifier. This some times get correct, other times not.
string_format uses php's sprintf() internally and thus inherits all
bugs and limitations from it.
for example: http://bugs.php.net/bug.php?id=35442
> I can't seem
> to find why this is, but here is code that should reproduce said problem:
>
> {% assign var="vat" value="0.525" %}
> {% assign var="total" value="10.95" %}
> {% math equation="x+y" x=$total y=$vat assign="total_total" %}
> {% $vat %}<br/>
> {% $vat|string_format:"%.2f" %}<br/>
> {% $total %}<br/>
> {% $total|string_format:"%.2f" %}<br/>
> {% $total_total %}<br/>
> {% $total_total|string_format:"%.2f" %}<br/>
>
> Expected output
>
> 0.525
> 0.53
> 10.95
> 10.95
> 11.475
> 11.48
>
> Actual output
> 0.525
> 0.53
> 10.95
> 10.95
> 11.475
> 11.47
>
> --
> Jonathan Lozinski
> Senior Developer
>
> SBsquared Limited
> The Old Forge
> Hoults Estate
> Walker Road
> Newcastle upon Tyne
> NE6 1AB
>
> T: +44(0)845 330 7201
> F: +44(0)870 460 4937
>
> W: www.sbsquared.com
> E: jl@sbsquared.com
>
> *********************************************************************
> This message (including any attachments) is confidential and may be
> legally privileged. If you are not the intended recipient, you should
> not disclose, copy or use any part of it - please delete all copies
> immediately and notify SBsquared Limited on +44 (0)845 330 7201.
>
> SBsquared is registered in England and Wales.
> Registered Office: Studio 5, The Old Forge, Hoults Estate,
> Walker Road, Newcastle upon Tyne, NE6 1AB
> *********************************************************************
>
> --
> Smarty Development Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php