Skip to content

Instantly share code, notes, and snippets.

@schmidt1024
Last active June 8, 2021 14:52
Show Gist options
  • Save schmidt1024/37d29cd2b58548b6020f65b5bb3e706e to your computer and use it in GitHub Desktop.
Save schmidt1024/37d29cd2b58548b6020f65b5bb3e706e to your computer and use it in GitHub Desktop.
math round in typescript
// 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;
};
@rsurjano
Copy link

it works!, thank you!

@leonardoalbanez
Copy link

it works! Better off Math.round()!

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