You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+22-19Lines changed: 22 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,4 @@
1
1
# big.js
2
-
[](#backers)
3
-
[](#sponsors)
4
2
5
3
**A small, fast JavaScript library for arbitrary-precision decimal arithmetic.**
6
4
@@ -17,27 +15,32 @@ The little sister to [bignumber.js](https://github.com/MikeMcl/bignumber.js/) an
17
15
- No dependencies
18
16
- Comprehensive [documentation](http://mikemcl.github.io/big.js/) and test set
19
17
20
-
## Install
21
-
22
-
[Node.js](http://nodejs.org) users can install from the [npm](https://www.npmjs.com/package/big.js) registry using
23
-
24
-
$ npm install --save big.js
25
-
26
-
## Use
18
+
## Set up
27
19
28
20
The library is the single JavaScript file *big.js* (or *big.min.js*, which is *big.js* minified).
29
21
30
-
It can be loaded via a script tag in an HTML document for the browser
22
+
Browser:
23
+
24
+
```html
25
+
<scriptsrc='path/to/big.js'></script>
26
+
```
31
27
32
-
<script src='./relative/path/to/big.js'></script>
28
+
[Node.js](http://nodejs.org):
33
29
34
-
or as a CommonJS, Node.js or AMD module using `require`.
30
+
```bash
31
+
$ npm install big.js
32
+
```
35
33
36
-
var Big = require('big.js');
34
+
```javascript
35
+
constBig=require('big.js');
36
+
```
37
37
38
-
If using an ES6 transpiler, or Node.js with the [`--experimental-modules`](https://nodejs.org/api/esm.html) flag, try
38
+
ES6 module (*big.mjs*):
39
39
40
-
import Big from 'big.js';
40
+
```javascript
41
+
importBigfrom'big.js';
42
+
```
43
+
## Use
41
44
42
45
*In all examples below, `var`, semicolons and `toString` calls are not shown. If a commented-out value is in quotes it means `toString` has been called on the preceding expression.*
43
46
@@ -69,7 +72,7 @@ Like JavaScript's Number type, there are `toExponential`, `toFixed` and `toPreci
69
72
x.toPrecision(5) // "255.50"
70
73
71
74
The arithmetic methods always return the exact result except `div`, `sqrt` and `pow`
72
-
(with negative exponent), as these are the methods which involve division.
75
+
(with negative exponent), as these methods involve division.
73
76
74
77
The maximum number of decimal places and the rounding mode used to round the results of these methods is determined by the value of the `DP` and `RM` properties of the `Big` number constructor.
75
78
@@ -115,14 +118,14 @@ For the browser, see *single-test.html* and *every-test.html* in the *test/brows
115
118
116
119
## Performance
117
120
118
-
The *perf* directory contains two old applications and a *lib* directory containing the BigDecimal libraries used by both.
121
+
The *perf* directory contains two legacy applications and a *lib* directory containing the BigDecimal libraries used by both.
119
122
120
123
*big-vs-bigdecimal.html* tests the performance of big.js against the JavaScript translations of two versions of BigDecimal, its use should be more or less self-explanatory.
The BigDecimal in the npm registry is the GWT version. Despite its seeming popularity I have found it to have some serious bugs, see the Node.js script *perf/lib/bigdecimal_GWT/bugs.js* for examples of flaws in its *remainder*, *divide* and *compareTo* methods.
128
+
The BigDecimal in the npm registry is the GWT version. It has some bugs, see the Node.js script *perf/lib/bigdecimal_GWT/bugs.js* for examples of flaws in its *remainder*, *divide* and *compareTo* methods.
126
129
127
130
*bigtime.js* is a Node.js command-line application which tests the performance of big.js against the GWT version of
128
131
BigDecimal from the npm registry.
@@ -153,7 +156,7 @@ will create *big.min.js*.
153
156
154
157
The [DefinitelyTyped](https://github.com/borisyankov/DefinitelyTyped) project has a Typescript type definitions file for big.js.
155
158
156
-
$ npm install --save @types/big.js
159
+
$ npm install @types/big.js
157
160
158
161
Any questions about the TypeScript type definitions file should be addressed to the DefinitelyTyped project.
0 commit comments