Re: Re: [PHP] Round with money_format
| From: | Cyril Lopez | Date: | Mon, 19 Sep 2011 09:09:40 +0000 |
| Subject: | Re: Re: [PHP] Round with money_format | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-314936@lists.php.net to get a copy of this message | ||
2011/9/17 Bill Guion <bguion@comcast.net>:
> On Sep 17, 2011, at 3:46 AM, Cyril Lopez wrote:
>
>> From: Cyril Lopez <cyril@nethik.fr>
>> Date: September 16, 2011 10:58:28 AM EDT
>> To: php-general@lists.php.net
>> Subject: Round with money_format
>>
>> Hi,
>>
>> Can someone help me understand how money_format() rounds numbers ?
>>
>> <?php
>> setlocale(LC_ALL, 'fr_FR.UTF-8');
>> $price = 12.665;
>> echo money_format('%i',$price);
>> // 12.66 EUR, 12.67 EUR expected
>>
>> $price2 = 12.666;
>> echo money_format('%i',$price2);
>> // 12.67 EUR, ok
>>
>> echo round($price,2);
>> // 12.67, ok
>> echo round($price2,2);
>> // 12.67, ok
>> ?>
>>
>> Misconfiguration ? Bug ?
>> Thanks !
>>
>> Cyril
>>
>> Config :
>> Debian Lenny, PHP 5.3.8
>
> As someone else pointed out, rounding rules vary by locale, but I was taught 40+ years ago in
> graduate school programming class, 4 rounds down, 6 rounds up, and 5 rounds to the even number. This
> means 65 rounds to 6, while 75 rounds to 8. Your example seems to follow that rule.
Mmh ok. In french we call us "banking round" but the "infinite round"
(PHP_ROUND_HALF_UP) is more usual ?
Thanks all. But... Last question, what kind of round do you use for
pricing information, shop, bank requests ?
Cyril