Skip to content

Instantly share code, notes, and snippets.

@rashid327
Created March 10, 2020 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rashid327/14122d2c72ca998d7245d77b20bbae29 to your computer and use it in GitHub Desktop.
Save rashid327/14122d2c72ca998d7245d77b20bbae29 to your computer and use it in GitHub Desktop.
Round value in JavaScript upto 6 decimal places
var val = 21.877768666
Math.round(val * 1000000) / 1000000);
Output:
21.877769
@rashid327
Copy link
Author

var val = 21.877768666
Math.round(val * 100) / 100);

Output:
21.88

@rashid327
Copy link
Author

var val = 21.877768666
Math.round(val * 1000) / 1000);

Output:
21.878

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment