10 examples of 'javascript round to 3 decimal places' in JavaScript

Every line of 'javascript round to 3 decimal places' 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}
17function roundTo(value, places) {
18 var mult = Math.pow(10, places);
19 return Math.round(value * mult) / mult;
20}
11function roundNumber(number,decimalPlaces) //Used to round a number to a certain number of decimal places.
12{
13var placeSetter = Math.pow(10, decimalPlaces);
14number = Math.round(number * placeSetter) / placeSetter;
15return number;
16}
1694function precisionRound(number, precision) {
1695 var factor = Math.pow(10, precision);
1696 return Math.round(number * factor) / factor;
1697}
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}
157static round(value, decimals) {
158 return Number(`${Math.round(`${value}e${decimals}`)}e-${decimals}`)
159}
5export function roundTo4Decimals(x) {
6 return Math.round(x * 10000.0) / 10000.0
7}
590function round(num, precision) {
591 return Math.round(num * Math.pow(10, precision)) / Math.pow(10, precision);
592}
422function roundFloat(n: number, places: number): number {
423 return Math.round(10 ** places * n) * (10 ** -places);
424}

Related snippets