MikeMcl / bignumber.js

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

How to floor without format #313

Closed longhoangwkm closed 2 years ago

longhoangwkm commented 2 years ago

Hi, I checked solution from https://github.com/MikeMcl/bignumber.js/issues/69

y = new BigNumber('1234567.898765');
y.toFormat(2, BigNumber.ROUND_DOWN);   // '1,234,567.89'
y.toFormat(2, 1);                      // '1,234,567.89'

But that is not solution what I looking for. I wanna floor without comma. Is there any way to do

Expected result: 1234567.89

MikeMcl commented 2 years ago

Please don't link old issues. Issues are not the place to learn from.

There is a decimalPlaces method to round a BigNumber to a specified number of decimal places.

y = new BigNumber('1234567.898765');
y = y.decimalPlaces(2, BigNumber.ROUND_FLOOR);
y.toString();    // '1234567.89'

Please ask any further usage questions on a website like Stack Overflow.

longhoangwkm commented 2 years ago

Thanks