Comments (3)
I apologise if you were offended my my quick closing.
The methods which could use a global ROUNDING_DP
setting if no arguments were passed already have default behaviour that I think is useful.
If, as you suggest, the round
method used ROUNDING_DP
if no argument was passed, then that would break compatibility with JavaScript's Math.round
which rounds to an integer.
Similarly, the link I posted above explains that calling toFixed
without any arguments is useful for when toString
returns exponential notation and the user wants fixed-point notation but no rounding.
The config(10, 4)
syntax was kept in for backwards compatibility, and it's a lot less verbose.
Criticism of the library and its API is encouraged, and you are welcome to explain or justify your position further.
from bignumber.js.
Rather than
BigNumber.config({ DECIMAL_PLACES: 10 });
BigNumber.config(null, BigNumber.ROUND_HALF_UP):
you can use
BigNumber.config({ DECIMAL_PLACES: 10, ROUNDING_MODE: BigNumber.ROUND_HALF_UP });
or
BigNumber.config(10, BigNumber.ROUND_HALF_UP);
or just
BigNumber.config(10, 4);
Anyway, #22 discusses the behaviour of toFixed()
, and I don't see much to be gained from having a ROUNDING_DP
setting that applies to it and also presumably to toExponential
and toPrecision
.
Incidentally, you can also pass a rounding mode to those methods, for example
value.toFixed(8, BigNumber.ROUND_DOWN);
or
value.toFixed(8, 1);
Thanks for the feedback.
from bignumber.js.
My application is huge and it would be very convenient for me to change dp centrally like you like the convenience of changing rm globally.
See in my opinion
if dp is omitted, or is null or undefined, the return value is n rounded to a whole number.
if rm is omitted, or is null or undefined, ROUNDING_MODE is used.
it should say the same for dp. if dp is omitted or is null or undefined, ROUNDING_DP is used, if not set, the return value is n rounded to a whole number.
In addition to being more streamlined and coherent this way, I just dont see much financial nor science application that would want to use BigNumber for the sake of using integers without floating point (whole numbers) which by default is handled pretty well by binary arithmetics last time I checked.
Also to conclude my rambling about coherence, why did you introduce syntax like .config(10,4)? In my opinion the entropy of such syntax converges towards zero.
Hope you can stand critisism, don't mistake it for a lack of gratitude for your work, which it isn't. Yet, judging by the speed of this issue gotten closed, the last sentence may be justified.. :-)
from bignumber.js.
Related Issues (20)
- Using version 9.1.1, run new BigNumber(0).exponentiatedBy('-12345678901234567890123456789012345678901234567890').valueOf() Is return to infinity normal? HOT 1
- Issue toNumber() function round up when number is too big (v9.1.1) HOT 2
- Division on exponential values leads to infinite loop HOT 3
- 负数加减乘除不好用 HOT 1
- [Feature Request]: Can we support `toBigInt`?
- Type error HOT 2
- Big Number (toFixed,dp,decimalPlaces,toFormat) - Chrome Update Issue 115.0.5790.102 HOT 24
- Minus sign in formatted strings HOT 2
- wrong calculation result on multipliedBy/times methods HOT 1
- toNumber does not respect ROUNDING_MODE HOT 11
- Calculation error HOT 1
- Is there any other way to handle new BigNumber(999999999999999999999) without using strings? HOT 2
- Difference between multipliedBy and dividedBy behaviors HOT 2
- Different result between toFixed and toNumber HOT 1
- Can't convert to Base64 HOT 1
- Tree shake commonjs version from mjs version HOT 1
- toFixed error
- [Bug] Return Type of Methods HOT 1
- Logarithms (I know there is another issue about this)
- toString() default base is not 10? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bignumber.js.