An open API service indexing awesome lists of open source software.

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

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
// ...
```