Browse - Programming Tips - javaScript: how can I limit the number of decimal digits when displaying a number?Date: 2018apr7 Language: javaScript Keywords: dollars, cents, financial, round Q. javaScript: how can I limit the number of decimal digits when displaying a number? A. Use Number.toFixed() like thisconst n = 1.23456789; console.log(n.toFixed(2));Will display1.23Note that toFixed() requires a number and it returns a string. More info https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed Add a commentSign in to add a comment![]()
|