Last active
June 8, 2021 14:52
-
-
Save cod3cow/37d29cd2b58548b6020f65b5bb3e706e to your computer and use it in GitHub Desktop.
math round in typescript
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
// round(1234.5678, 2); // 1234.57 | |
round(number, precision) { | |
var factor = Math.pow(10, precision); | |
var tempNumber = number * factor; | |
var roundedTempNumber = Math.round(tempNumber); | |
return roundedTempNumber / factor; | |
}; |
it works! Better off Math.round()!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it works!, thank you!