Format php number

Asked

Viewed 100 times

3

I have the variable $valor who returns me

10,00

Needed to format this number to

10.00

In place of the comma , stitch .

I tried to use the function number_format($valor, 2, '.', '') but it’s making a mistake and I can’t.

Someone has a solution?

Error found:

"A non well formed numeric value encountered in line 15 "

2 answers

7


Do it like this:

$novoValor = str_replace(',', '.', $valor);
  • 1

    Perfect! It worked.

1

Even putting the answer up as right, your job number_format is in wrong use:

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

It does not accomplish the CAST of a number, just format it. So that I put, puts a number ready for reading in the Brazilian molds.

Browser other questions tagged

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