Giter Site home page Giter Site logo

Comments (3)

MikeMcl avatar MikeMcl commented on June 11, 2024 1

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.

MikeMcl avatar MikeMcl commented on June 11, 2024

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.

wethinkagile avatar wethinkagile commented on June 11, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.