Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
383 views
in Technique[技术] by (71.8m points)

round to 3 decimal points in javascript/jquery

How will i round margin_total to 3 decimal places?

margin_total = margin_total + parseFloat(marginObj.value);
document.getElementById('margin_total').value = margin_total;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use num.toFixed(d) to convert a number into the String representation of that number in base 10 with d digits after the decimal point, in this case,

margin_total.toFixed(3);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...