Skip to content

Commit c29c80c

Browse files
committed
Support underscores as separators
1 parent 69e91fe commit c29c80c

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ The methods that return a Decimal can be chained.
122122

123123
```js
124124
x.dividedBy(y).plus(z).times(9).floor()
125-
x.times('1.23456780123456789e+9').plus(9876.5432321).dividedBy('4444562598.111772').ceil()
125+
x.times('1.23456780123456789e+9').plus(9876.5432321).dividedBy('4_444_562_598.111772').ceil()
126126
```
127127

128128
Many method names have a shorter alias.
@@ -235,7 +235,7 @@ then
235235
npm run build
236236
```
237237

238-
will create *decimal.min.js*, and a source map will also be added to the *doc* directory.
238+
will create *decimal.min.js* and a source map.
239239

240240
## Licence
241241

decimal.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3596,8 +3596,11 @@
35963596
*/
35973597
function parseOther(x, str) {
35983598
var base, Ctor, divisor, i, isFloat, len, p, xd, xe;
3599-
3600-
if (str === 'Infinity' || str === 'NaN') {
3599+
3600+
if (str.indexOf('_') > -1) {
3601+
str = str.replace(/(\d)_(?=\d)/g, '$1');
3602+
if (isDecimal.test(str)) return parseDecimal(x, str);
3603+
} else if (str === 'Infinity' || str === 'NaN') {
36013604
if (!+str) x.s = NaN;
36023605
x.e = NaN;
36033606
x.d = null;

decimal.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3593,7 +3593,10 @@ function parseDecimal(x, str) {
35933593
function parseOther(x, str) {
35943594
var base, Ctor, divisor, i, isFloat, len, p, xd, xe;
35953595

3596-
if (str === 'Infinity' || str === 'NaN') {
3596+
if (str.indexOf('_') > -1) {
3597+
str = str.replace(/(\d)_(?=\d)/g, '$1');
3598+
if (isDecimal.test(str)) return parseDecimal(x, str);
3599+
} else if (str === 'Infinity' || str === 'NaN') {
35973600
if (!+str) x.s = NaN;
35983601
x.e = NaN;
35993602
x.d = null;

doc/API.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ <h5 id="decimal">
301301

302302
new Decimal(0.046875) // '0.046875'
303303
new Decimal('0.046875000000') // '0.046875'
304+
new Decimal('0.046_875_000_000') // '0.046875'
304305

305306
new Decimal(4.6875e-2) // '0.046875'
306307
new Decimal('468.75e-4') // '0.046875'

0 commit comments

Comments
 (0)