10 examples of 'jquery round to 2 decimal' in JavaScript

Every line of 'jquery round to 2 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

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}
32function round2(number) {
33 return Math.round(number * 100) / 100;
34}
157static round(value, decimals) {
158 return Number(`${Math.round(`${value}e${decimals}`)}e-${decimals}`)
159}
36function roundNumber(num, decimals) {
37 num = num || 0;
38 if (typeof num === 'number') {
39 return parseFloat(num.toFixed(decimals));
40 } else {
41 return roundArray(num, decimals);
42 }
43}
17function roundTo(value, places) {
18 var mult = Math.pow(10, places);
19 return Math.round(value * mult) / mult;
20}
118export function round1(num: number) {
119 if (+num.toPrecision(4) === (num | 0)) return num;
120 else return num.toPrecision(4);
121}
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}
140export function roundTo(num: number, decimals: number = 2): number {
141 const a = Math.pow(10, decimals);
142 return Math.round(num * a) / a;
143}

Related snippets