Format number from 3200 to 3,200 with PHP

Asked

Viewed 228 times

-1

I have to transform values like:

3200
5000
10000
13000
100000

in

3.200
5.000
10.000
13.00
100.000

I tried to use the function number_formatof PHPbut I could not do it correctly. How can I solve this problem ?

1 answer

1


You can elaborate as follows:

function formata_valor($valor){
    if($valor!=NULL){
        echo number_format($valor, 0, ',', '.');
    } else {
        echo "Nenhum valor foi preenchido.";
    }
}
echo formata_valor("10000"); // output 10.000

Reference documentation: http://php.net/number_format

  • It worked out! Thank you.

  • No reason Alisson, the mood!

  • 2

    Here is the suggestion to explain what each parameter does to value the answer. Not everyone reads the recommended links. In fact not everyone reads the answers carefully :)

  • Relax, I put the documentation as a reference too... But as I responded quickly, I ended up not completing much of the explanation. But I appreciate your touch! :)

  • If completed, it is even easier to use to close future duplicates with the same doubt (and attracts more votes of "toast") :)

  • Okay, I’ll make a better explanation ;)

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.