10 examples of 'javascript round to 2 digits' in JavaScript

Every line of 'javascript round to 2 digits' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
11function roundOne(decimalNumber) {
12 return roundTo(decimalNumber, 1);
13}
32function round2(number) {
33 return Math.round(number * 100) / 100;
34}
1export function round(value: any, decimals: any) {
2 if (!decimals) decimals = 0;
3 return Number(Math.round(Number(value + 'e' + decimals)) + 'e-' + decimals);
4}
59function round(value, decimals) {
60 return Number(Math.round(value + 'e' + decimals) + 'e-' + decimals);
61}
185function round2(n) {
186 return Math.round(n * 100) / 100;
187}
118export function round1(num: number) {
119 if (+num.toPrecision(4) === (num | 0)) return num;
120 else return num.toPrecision(4);
121}
456function roundPrecision (x, d, places = 2) {
457 return (Math.floor(x * d) / d).toFixed(places);
458}
277function round_decimals(original_number, decimals) {
278 var result1 = original_number * Math.pow(10, decimals)
279 var result2 = Math.round(result1)
280 var result3 = result2 / Math.pow(10, decimals)
281 return pad_with_zeros(result3, decimals)
282}
157static round(value, decimals) {
158 return Number(`${Math.round(`${value}e${decimals}`)}e-${decimals}`)
159}
1694function precisionRound(number, precision) {
1695 var factor = Math.pow(10, precision);
1696 return Math.round(number * factor) / factor;
1697}

Related snippets