Giter Site home page Giter Site logo

Comments (3)

MikeMcl avatar MikeMcl commented on June 11, 2024

Well, I like toEngineering, but as engineering notation is a form of exponential notation it seems appropiate to handle it using toExponential.

The problem is that toExponential already takes a rounding mode as a second argument, and I don't want any methods here to have more than two parameters.

That leaves the option of using BigNumber.config. For example,

var n = new BigNumber(123);
n.toExponential();    // '1.23e+2'

BigNumber.config({ ENGINEERING: true });
n.toExponential();    // '0.123e+3'

from bignumber.js.

mgkr avatar mgkr commented on June 11, 2024

That (using config) might work.
Instead of a bool though, why not an integer - So one would have the chance of going multiples of 6 (or whatever) as well.
Very niche case if any would ever need that (I don't think I ever would).
But if making the change, it ought to be negligible to allow for an int setting over just a bool, so no reason to limit it imo.

PS:
Your example (123) is a bit misleading/wrong.
It should be output as just "123" - While 1234 would be 1.234e+3

from bignumber.js.

MikeMcl avatar MikeMcl commented on June 11, 2024

Yes, I was wondering how values less than 1000 should be properly handled, but having a toExponential return value without an exponent doesn't seem appropiate.

On second thoughts I think using toEngineering would be best, though not with an arbitrary multiple.

I think its a good suggestion and I'll put in on my to-do list and close for now.

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.