Last active
July 1, 2022 07:19
-
-
Save lelinhtinh/4bd11f5f82f5d5b1f056 to your computer and use it in GitHub Desktop.
Làm tròn số thập phân với javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* http://www.jacklmoore.com/notes/rounding-in-javascript/ */ | |
function round(value, decimals) { | |
return Number(Math.round(value + 'e' + decimals) + 'e-' + decimals); | |
} | |
/* http://stackoverflow.com/a/11832950 */ | |
Math.round(num * 100) / 100; | |
/* http://stackoverflow.com/a/12830454 */ | |
parseFloat("123.456").toFixed(2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment