1

I am using php. I am trying to format a number based on the user culture. what I ideally would love would be a function to which I could give the culture and the number as parameters and it would automatically format the number based on the culture but I have not found anything like that.

So I tried using setlocale(LC_NUMERIC, myCulture), then call localeconv() to know which decimal separator and thousands separator etc to use the number_format function. I put results on variables, and they are all the same! i.e. I made:

setlocale(LC_NUMERIC, "en-US");
$result1 = localeconv();
setlocale(LC_NUMERIC, "fr-FR");
$result2 = localeconv();

$result1 and $result2 are the exact same things! What am I doing wrong? any idea? Thank you for your help,

Martin

martin
  • 30
  • 6
  • What do the calls to `setlocale` return? – Jim Jul 09 '13 at 13:04
  • This will not work on Windows-based systems.. – Pieter Jul 09 '13 at 13:05
  • check : http://stackoverflow.com/questions/2906326/setlocale-to-fr-fr-in-php-and-number-formatting – rags Jul 09 '13 at 13:10
  • I tried what he said, the point is that setlocale() returns 0. And I wanna do the contrary of what he is trying to, convert an us formatted number to user culture formatted number. Result is still the same: us format number – martin Jul 09 '13 at 13:21

1 Answers1

1

check the return value of setlocale(LC_NUMERIC, "en-US");

$val = setlocale(LC_NUMERIC, "en-US");
if ($val === FALSE) //locale is not available

if the $val is returning FALSE for linux distributions run the following command

locale-gen fr_FR.utf8 and it should install the locale for you.

DevZer0
  • 13,433
  • 7
  • 27
  • 51