Number
object has the toFixed
method that allows display a number with a fixed amount of digits after the decimal point. Unfortunately, it doesn't round the number.
function tf(n) {
out.innerHTML += n.toFixed(3) + '<br>';
}
tf(4 ); // 4.000
tf(4.2 ); // 4.200
tf(4.1004); // 4.100
tf(4.1009); // 4.100
Links
Source code on github
No comments:
Post a Comment