Search code examples
phpnumbersnumber-formatting

PHP - number_format float number


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


Solution

  • 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