|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-09-22 21:32 UTC] kyegil at gmail dot com
Description: ------------ --- From manual page: http://www.php.net/numberformatter.formatcurrency#refsect1-numberformatter.formatcurrency-description --- php NumberFormatter->formatCurrency() gives unexpected results when rounding decimals Test script: --------------- $fmt = new NumberFormatter( 'en_GB', NumberFormatter::CURRENCY ); echo $fmt->formatCurrency("0.005", "GBP")."\n"; echo $fmt->formatCurrency("0.015", "GBP")."\n"; echo $fmt->formatCurrency("0.025", "GBP")."\n"; echo $fmt->formatCurrency("0.035", "GBP")."\n"; echo $fmt->formatCurrency("0.045", "GBP")."\n"; echo $fmt->formatCurrency("0.055", "GBP")."\n"; Expected result: ---------------- £0.01 £0.02 £0.03 £0.04 £0.05 £0.06 Actual result: -------------- £0.00 £0.02 £0.02 £0.04 £0.04 £0.06 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 17 07:00:01 2025 UTC |
I see. But setting Rounding Mode to Half Up still gives me exactly the same result (and so do all the other rounding modes): $fmt = new NumberFormatter('en_GB', NumberFormatter::CURRENCY); $fmt->setAttribute(NumberFormatter::ROUNDING_MODE, NumberFormatter::ROUND_HALFUP); echo $fmt->formatCurrency("0.005", "GBP")."\n"; echo $fmt->formatCurrency("0.015", "GBP")."\n"; echo $fmt->formatCurrency("0.025", "GBP")."\n"; echo $fmt->formatCurrency("0.035", "GBP")."\n"; echo $fmt->formatCurrency("0.045", "GBP")."\n"; echo $fmt->formatCurrency("0.055", "GBP")."\n";