const roundWithScale = (value: number, scale: number) => {
return Math.round(value * 10 ** scale) / 10 ** scale;
};
roundWithScale(1.456789, 0) // 1
roundWithScale(1.456789, 1) // 1.5
roundWithScale(1.456789, 2) // 1.46
roundWithScale(1.456789, 3) // 1.457
More than 3 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme