@extra-number/round
TypeScript icon, indicating that this package has built-in type declarations

2.0.27 • Public • Published

Rounds number to specific precision.

Also helps to deal with number precision problems.
This is part of package extra-number.

number.round(n, [pre]);
// n:   a number
// pre: to precision (1e-12)
const number = require('extra-number');

/* 1. round to specific precision */
number.round(9.135, 1);
// 9

number.round(9.135, 1e-2);
// 9.14

number.round(9.1357, 0.05);
// 9.15

 
/* 2. round precision errors */
0.1*0.2
// 0.020000000000000004

number.round(0.1*0.2);
// 0.02

references

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.0.27
    15
    • latest

Version History

Package Sidebar

Install

npm i @extra-number/round

Weekly Downloads

102

Version

2.0.27

License

MIT

Unpacked Size

3.42 kB

Total Files

9

Last publish

Collaborators

  • npm