I am trying to localise currency display in a number of places including in a view that is part of a list.
Using formatCurrency I get a number of different results depending on what I do, none of them optimal. It seems that the format routine is treating the number as a float. The number is decimal(12,2) in the db.
The amounts are displayed fine when I just display the data. The problem is that the client wants the formatting according to the local European rules with thousands seperators, so I am trying formatCurrency.
I dont think so - I have tried a number of different locales with the same result. With “en” I see ‘currencyFormat’ => ‘¤#,##0.00;(¤#,##0.00)’ - that looks ok to me. Its something to do with the number being treated as a long rather than a string somewhere.
Problem still there with the latest version of yii. It is clear that your setup is giving a different result from round() to mine - hence the issue. I will research this in the php forums, but it will no doubt affect someone else sometime I would think.
round() should work too… if the second parameter is 2 it should return a number with 2 decimals… can you check the value of $format[‘maxDecimalDigits’] in your case where you are getting numbers like 529.9199999999999591…
Could you log on your parseFormat function in CNumberFormatter, the Pattern that is passed to the function and the result? ie: echo $pattern on line 206, and echo CVarDumper::dumpAsString($format) on line 278
Theres quite a bit floating around about the issues with floats, but none of this explains why I see the problem and others dont! Very simply - why does round() give me this error and number_format() not? Anyway - by changing the float() to number_format in CNumberFormatter I get around this issue - is there any reason why this cant be done in the framework?