Format php number

3

I have the $valor variable that returns me

10,00

I needed to format this number for

10.00

Instead of the comma , put a dot .

I tried to use the function number_format($valor, 2, '.', '') but it is giving error and I can not.

Does anyone have a solution?

Error encountered:

"A non well formed numeric value encountered in line 15 "
    
asked by anonymous 28.12.2016 / 17:24

2 answers

7

Do this:

$novoValor = str_replace(',', '.', $valor);
    
28.12.2016 / 17:28
1

Even putting the above answer as certain, your number_format function is misused:

number_format($valor, 2, ',', '.');

It does not%% of a number, it just formats it. That way I put it, put a number ready for reading in the Brazilian mold.

    
28.12.2016 / 18:05