Re: string_format rounding error..
messju mohr <[email protected]> Tue, 23 Jan 2007 12:41:21 +0100
| Newsgroups | gmane.comp.php.smarty.devel |
|---|---|
| Message-ID | <[email protected]> |
In-Reply-To: <[email protected]> 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: [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 > ********************************************************************* > > -- > Smarty Development Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php -- Smarty Development Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php