Comments (3)
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.
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.
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)
- 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 2
- 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.