Support underscores as separators

pull/186/head
Michael Mclaughlin 3 years ago
parent 69e91fecd2
commit c29c80c6e3

@ -122,7 +122,7 @@ The methods that return a Decimal can be chained.
```js
x.dividedBy(y).plus(z).times(9).floor()
x.times('1.23456780123456789e+9').plus(9876.5432321).dividedBy('4444562598.111772').ceil()
x.times('1.23456780123456789e+9').plus(9876.5432321).dividedBy('4_444_562_598.111772').ceil()
```
Many method names have a shorter alias.
@ -235,7 +235,7 @@ then
npm run build
```
will create *decimal.min.js*, and a source map will also be added to the *doc* directory.
will create *decimal.min.js* and a source map.
## Licence

@ -3596,8 +3596,11 @@
*/
function parseOther(x, str) {
var base, Ctor, divisor, i, isFloat, len, p, xd, xe;
if (str === 'Infinity' || str === 'NaN') {
if (str.indexOf('_') > -1) {
str = str.replace(/(\d)_(?=\d)/g, '$1');
if (isDecimal.test(str)) return parseDecimal(x, str);
} else if (str === 'Infinity' || str === 'NaN') {
if (!+str) x.s = NaN;
x.e = NaN;
x.d = null;

@ -3593,7 +3593,10 @@ function parseDecimal(x, str) {
function parseOther(x, str) {
var base, Ctor, divisor, i, isFloat, len, p, xd, xe;
if (str === 'Infinity' || str === 'NaN') {
if (str.indexOf('_') > -1) {
str = str.replace(/(\d)_(?=\d)/g, '$1');
if (isDecimal.test(str)) return parseDecimal(x, str);
} else if (str === 'Infinity' || str === 'NaN') {
if (!+str) x.s = NaN;
x.e = NaN;
x.d = null;

@ -301,6 +301,7 @@ new Decimal('0xff.8') // '255.5'
new Decimal(0.046875) // '0.046875'
new Decimal('0.046875000000') // '0.046875'
new Decimal('0.046_875_000_000') // '0.046875'
new Decimal(4.6875e-2) // '0.046875'
new Decimal('468.75e-4') // '0.046875'

Loading…
Cancel
Save