Skip to content

Rewrite Number.prototype.toFixed to make it consistent across any environement and add more precision

License

Notifications You must be signed in to change notification settings

dreamdevil00/tofixed

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Number.prototype.toFixed() rewrite

Description

As we know, Number.prototype.toFixed() has many problems due to precision.

For example, in NodeJS 8.11.3

(5.395).toFixed(2); // 5.39
-(5.395).toFixed(2); // -5.39
(1.395).toFixed(2); // 1.40
-(1.395).toFixed(2); // -1.4

and in IE9

(5.395).toFixed(2); // 5.40
-(5.395).toFixed(2); // -5.4
(1.395).toFixed(2); // 1.40
-(1.395).toFixed(2); // -1.4

This lib aims to make it consistent across any environment,

and above test result will be

(5.395).toFixed(2); // 5.40
-(5.395).toFixed(2); // -5.4
(1.395).toFixed(2); // 1.40
-(1.395).toFixed(2); // -1.40

How to use

Introduce it before your code

for example:

require('index');
// or
import './index.js';

// other codes
// ...

About

Rewrite Number.prototype.toFixed to make it consistent across any environement and add more precision

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published