setlocale to fr-FR in PHP and number formatting

Posted by bateman_ap on Stack Overflow See other posts from Stack Overflow or by bateman_ap
Published on 2010-05-25T16:00:53Z Indexed on 2010/05/25 16:21 UTC
Read the original article Hit count: 319

Filed under:
|
|

Hi, I am trying to create a French version of one of my sites. I have set setlocale(LC_ALL, 'fr_FR'); at the top of my page, and using strftime I am displaying dates correctly in the French style.

However I am having some problems with a number. Part of the page uses data I am getting from a Web Service. I am assigning a returned value to a var like this:

$overallRating = $returnArray['Overall'];

I am then using the following code later to format it to 1 decimal place

number_format($overallRating,1)

In the English version the overallRating value might be 7.5 and returns a value such as 7.5 (the reason for running it through the number_format is if it returns 7 I want it to display 7.0)

However in the French version if I print out the raw $overallRating value I get 7,5 which looks like it has translated it into french. This would be fine but if I run it through number_format I get the error:

Notice: A non well formed numeric value encountered in /sites/index.php  on line 250

Line 250 is the number_format line

I presume the translation to 7,5 is messing it up, but not sure how to solve this...

Using PHP 5.3 in case there is anything new that helps me

© Stack Overflow or respective owner

Related posts about php

Related posts about locale