Format money value from database

Asked

Viewed 65 times

1

I have an input with a mask where the user type the desired price and automatically is formatted. Before sending to the database, I transform this value so I can work with it with some arithmetic operation.

Example:

$preco = "2.199,99"

$preco = str_replace(".", "", $preco);
$preco = str_replace(",", ".", $preco);

//No final o valor inserido no banco de dados será 2199.99

This value, after registration, will appear in a table, I would like it to come in the same way as when it was formatted. Replace again the . for ,, but how will I insert a . for every three numbers?

1 answer

1


  • I didn’t know this function, thank you!

Browser other questions tagged

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