2
The idea is not to have to convert the result to two decimal places every time. Example:
var preco = 10.00
To show these decimal places, I have to put like this:
$("#preco").html("R$ " + preco.toFixed(2));
and then if I do any calculations:
preco += 10
$("#preco").html("R$ " + preco.toFixed(2));
Again I have to put the toFixed(2)
.
So the question is: Is there any way to always leave this variable with two decimal places, without having to use the toFixed()
several times?
You can create a function that returns any number already in the format with 2 decimals. But as stated in @Maniero’s reply, there’s no way to do it this way that the question proposes.
– Sam