https://github.com/dreamdevil00/tofixed
Rewrite Number.prototype.toFixed to make it consistent across any environement and add more precision
https://github.com/dreamdevil00/tofixed
precision tofixed
Last synced: about 1 year ago
JSON representation
Rewrite Number.prototype.toFixed to make it consistent across any environement and add more precision
- Host: GitHub
- URL: https://github.com/dreamdevil00/tofixed
- Owner: dreamdevil00
- License: mit
- Created: 2018-10-25T09:53:55.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-25T10:39:03.000Z (over 7 years ago)
- Last Synced: 2025-02-01T19:23:06.863Z (over 1 year ago)
- Topics: precision, tofixed
- Language: JavaScript
- Size: 38.1 KB
- Stars: 0
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Number.prototype.toFixed() rewrite
## Description
As we know, Number.prototype.toFixed() has many problems due to precision.
For example, in NodeJS 8.11.3
```javascript
(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
```javascript
(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
```javascript
(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:
```javascript
require('index');
// or
import './index.js';
// other codes
// ...
```