0

Please I have to made a small calculus using mysqli and php, and to return a float or a double value, so I've tried :

$notes = mysclass_sql::query("SELECT SUM(commentsNote) / COUNT(*) as c
                        FROM comments ")->fetch_object()->c;
return round( $notes , 2) ;

But this returns me a value like this 1,25 and not 1.25 even if I try using str_replace !!

I can't get out from this, please masters any help ?

Eric Petroelje
  • 59,820
  • 9
  • 127
  • 177
Sami El Hilali
  • 981
  • 3
  • 12
  • 21

2 Answers2

0

You want to use number_format().

$notes = mysclass_sql::query("SELECT SUM(commentsNote) / COUNT(*) as c
                    FROM comments ")->fetch_object()->c;
return(number_format($notes, 2, ".", ""));

fyi, this is the first hit if you google "php comma decimal".

octern
  • 4,825
  • 21
  • 38
0

You can try setting the locale -

setlocale (LC_ALL, "en-US");  // or "en_US", etc, depending on your server
Sam Dufel
  • 17,560
  • 3
  • 48
  • 51
  • On my system, `en-US` doesn't work but `en_US` does (and similarly for other locale strings). – octern Feb 08 '13 at 22:50
  • This answer makes a lot more sense than mine if you want to print all numbers in the new format. My answer is appropriate if you want to format only some specific numbers. – octern Feb 08 '13 at 22:51
  • *shrug, it depends on the OS. – Sam Dufel Feb 08 '13 at 22:53