PHP - convert strings to money

I am trying to convert a string to a money format using this function and trying to create something like this:

350000000

to

350.000.000,00

All my attempts have failed so far, being the last:

setlocale(LC_MONETARY, 'pt_PT.UTF-8@euro');
echo money_format('%.2n', $preco);

Any help would be greatly appreciated. Hooray!

+3
source share
2 answers

you can use number_format () as follows:

$number = 350000000;
$money_number = number_format($number,2,',','.');
+8
source

Perhaps you need to compile the locale definition files for the Portuguese language, it should look something like this:

localedef -ci pt_PT -f utf-8 pt_PT
+2
source

Source: https://habr.com/ru/post/1755590/


All Articles