1
I have the following script in my HTML, what it does is simply check a checkbox if it is selected or not and in case it is adding a value, my question is, how to make this value be formatted in currency? For example when instead of appearing 400,00 or 1,455,80 it appears all together as an integer in case 400 and 145580, how to show the values in real?
Script:
function check() {
var basic = 0;
var add = 0;
if(document.getElementById("cl45").checked) {
add += 145580;
}
if(document.getElementById("trigger").checked) {
add += 40000;
}
var p = basic + add;
var price ="R$ " + p;
document.getElementById('total2').innerHTML = price;
}
check();
price.toFixed(2)
That’s what you wanted?– Francisco
I don’t know, I started working with js now, I’m going to do some research on it, thanks.
– HBretone
What is the reason for this value with comma in the add script += 400,00; Because it does not enter value that javascript requires for calculations, ie 400.00 with decimal point?
– user60252
This value will be displayed to the user, the idea is that when he marks a checkbox add a value to a visible field, so that some checkboxs add 400,00 and other 1.455,80, would like the user can view the common real formatting and not that appeared "1455.8" or "400".
– HBretone
can you post html? this script is not complete, it is difficult to reproduce an example that we can test
– user60252
It is not necessary, I am taking a look at another similar question I believe that the answers from there can help me, since my question has been duplicated. If I don’t get anything open another question specifying my problem better, but thanks for the help.
– HBretone
see if my answer helps
– user60252
the question should not be changed because the answer becomes half meaningless
– user60252