1.0.1 • Published 11 months ago
tofixed-round-fix v1.0.1
toFixed rounding fix polyfill
Polyfill fix for Number.toFixed()
method incorrect rounding on certain cases when last significant digit is 5 and fixed length shortens fraction by one digit, as described in original David Kaye post.
Usage
// install
npm install tofixed-round-fix
// import on top of project
import "tofixed-round-fix"
Test cases:
// before
(1.015).toFixed(2) // "1.01"
(63.025).toFixed(2) // "63.02"
// after
(1.015).toFixed(2) // "1.02"
(63.025).toFixed(2) // "63.03"