Converting regional decimal numbers
| From: | C.F. Scheidecker Antunes | Date: | Sat, 24 Jul 2004 00:15:59 +0000 |
| Subject: | Converting regional decimal numbers | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-191709@lists.php.net to get a copy of this message | ||
Hello all,
I have a few users that use a different number format, other than the US one, which is 1.526,23 . That is, the comma is used as a separator for the fractional part of the number (.23) and the dot is used to separate
thousands. Therefore, I need to convert 1.526,23 to 1,526.23, invert the comma and the dot. Some numbers are formated correctly so nothing needs to be done, while other need that.
I have writen a function to perform that but it reads char by char and has test cases. I first check the position of the dot and the comma. It one is higher than the other than I need to convert, if not than I do
nothing. I would like to make it simpler and more efficent and for that I need some help from some of the PHP regex experts.
Can anyone help me with this matter?
Thanks in advance.