10 examples of 'javascript round to 1 decimal' in JavaScript

Every line of 'javascript round to 1 decimal' 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
this disclaimer
11function roundOne(decimalNumber) {
12 return roundTo(decimalNumber, 1);
13}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

118export function round1(num: number) {
119 if (+num.toPrecision(4) === (num | 0)) return num;
120 else return num.toPrecision(4);
121}
59function round(value, decimals) {
60 return Number(Math.round(value + 'e' + decimals) + 'e-' + decimals);
61}
1export function round(value: any, decimals: any) {
2 if (!decimals) decimals = 0;
3 return Number(Math.round(Number(value + 'e' + decimals)) + 'e-' + decimals);
4}
157static round(value, decimals) {
158 return Number(`${Math.round(`${value}e${decimals}`)}e-${decimals}`)
159}
33round() {
34 return new _ExactMath(arguments, 'round')._rounding();
35}
125static roundDecimal(number, precision) {
126 let factor = Math.pow(10, precision);
127 return Math.round(number * factor) / factor;
128}
590function round(num, precision) {
591 return Math.round(num * Math.pow(10, precision)) / Math.pow(10, precision);
592}
311function convertDecimal(value, surroundDecimalsWith) {
312 if (/^-?([0]|([1-9][0-9]*))(\.[0-9]+)?$/.test(value) == false) {
313 throw new Error("value supposed to be a decimal number but got: " + value);
314 }
315 if (surroundDecimalsWith) {
316 return {
317 value: value,
318 toJSON: function () {
319 return surroundDecimalsWith.str + value + surroundDecimalsWith.str;
320 }
321 };
322 }
323 else {
324 return value;
325 }
326}
135round(amount: number, decimals: number) {
136 return +amount.toFixed(decimals);
137}

Related snippets