MikeMcl / bignumber.js

A JavaScript library for arbitrary-precision decimal and non-decimal arithmetic
http://mikemcl.github.io/bignumber.js
MIT License
6.65k stars 742 forks source link

Any API to work with fixed numbers without converting it to String? #223

Closed imrefazekas closed 5 years ago

imrefazekas commented 5 years ago

Hey,

I would love to use bignumber.js to perform a lot of financial calculations including many-many fixation to several digits. I see the toFixed function which makes the magic but it convers the number to String. When I multiple then fix, then substract another value then fix again means a lot of string conversion and parse. Is there a way to eliminate the string-based operation?

balance.Physical = new BigNumber(balance.Debit).minus(balance.Credit).times(multiplier).toFixed( rounding )
balance.Available = new BigNumber(balance.Physical).minus(balance.Blocked).toFixed( rounding )

Current code contains 2 fix. 2 string conversion and parse which should be eliminated.:)

Thanks!

MikeMcl commented 5 years ago

Yes, see decimalPlaces.

imrefazekas commented 5 years ago

Ahh, thanks! Sorry for the trouble. :)