0

how can i format a float number, exemple 6099.99, to: 6,099.99 or 6.099,99

i've tried the function number_format() and money_format() like this:

number_format(6099.99,2,'.',',') // output 6,00

setlocale(LC_MONETARY, 'it_IT'); echo money_format('%.2n', $number) // output 6,00

Thx in advanced

  • 2
    I tried `echo number_format(6099.99,2,'.',',');` its give `6,099.99`? What's your problem? – xNoJustice Aug 14 '20 at 14:54
  • ___money_format___ **Warning** This function has been _DEPRECATED_ as of PHP 7.4.0. Relying on this function is highly discouraged. – RiggsFolly Aug 14 '20 at 14:57

1 Answers1

2

You just have the parameters the wrong way round. Param 3 is the decimal seperator and param 4 is the Thousands seperator

echo number_format(6099.99,2,',','.')
//   change params to         ^   ^

RESULT

6.099,99
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • In what manner? @AndrewHardiman – RiggsFolly Aug 14 '20 at 15:02
  • 1
    But I have added some explanation. If you means [this answer of yours](https://stackoverflow.com/a/63393095/2310830) There is no explanation of why you are suggesting to make whatever changes you made to the code @AndrewHardiman – RiggsFolly Aug 14 '20 at 15:06