string_format rounding error..
[email protected] (Jonathan Lozinski) Tue, 23 Jan 2007 11:31:49 +0000
| Newsgroups | php.smarty.dev |
|---|---|
| Message-ID | <[email protected]> |
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. 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: [email protected]
*********************************************************************
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
*********************************************************************