royNiladri / js-big-decimal

Work with large numbers on the client side with high precision.
https://www.npmjs.com/package/js-big-decimal
MIT License
156 stars 28 forks source link

Incorrect results from parsing an exponential form numbers #60

Closed eldereal closed 2 years ago

eldereal commented 2 years ago

Describe the bug

Incorrect result will When parsing exponential form numbers with following patters:

  1. integer mantissa (1e0, 1e1, 1e-1) results in a number with wrong dot position.
  2. negative mantissa (-1e1, -0.0134e-2 ) results in illegal number formats.

To Reproduce Run in a nodejs console:

> bigDecimal = require('js-big-decimal');
> new bigDecimal('1e0')
bigDecimal { value: '0.1' }
> new bigDecimal('1e1')
bigDecimal { value: '1' }
> new bigDecimal('-1e1')
bigDecimal { value: '-.1' }
> new bigDecimal('-0.0134e-2')
bigDecimal { value: '0.-00134' }

Expected behavior Correct numbers returned.

Additional context Tested in latest development branch. A bug fix will submitted later.