-
Notifications
You must be signed in to change notification settings - Fork 929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Format scientific notation returns NaN if negative exponential is beyond 7 points #512
Comments
Same here 😭 |
For helping to troubleshoot: https://jsfiddle.net/86syrqL3/ Happens even with a exponential value produced by numeral itself. Probably worth doing a diff on the two versions to see what changed. |
We are also having this problem! |
The reason is hidden in the numeral.js, row 207: int = numeral._.toFixed(value, 0, roundingFunction); , which itself leads us to the implementation of toFixed method, defined in rows 380-406: toFixed: function(value, maxDecimals, roundingFunction, optionals) {
var splitValue = value.toString().split('.'),
minDecimals = maxDecimals - (optionals || 0),
boundedPrecision,
optionalsRegExp,
power,
output;
// Use the smallest precision value possible to avoid errors from floating point representation
if (splitValue.length === 2) {
boundedPrecision = Math.min(Math.max(splitValue[1].length, minDecimals), maxDecimals);
} else {
boundedPrecision = minDecimals;
}
power = Math.pow(10, boundedPrecision);
// Multiply up by precision, round accurately, then divide and use native toFixed():
output = (roundingFunction(value + 'e+' + boundedPrecision) / power).toFixed(boundedPrecision);
if (optionals > maxDecimals - boundedPrecision) {
optionalsRegExp = new RegExp('\\.?0{1,' + (optionals - (maxDecimals - boundedPrecision)) + '}$');
output = output.replace(optionalsRegExp, '');
}
return output;
} Suppose we have a value equal to 1e-7 and we want to show it as an integer (this means, that we set maxDecimals to zero). output = (roundingFunction(value + 'e+' + boundedPrecision) / power).toFixed(boundedPrecision); Which is in our case: output = (Math.round(1e-6 + 'e+' + 0) / 1).toFixed(0) // gives '0' But once we use 1e-7 we might be suprpised with the outcome, because output = (Math.round(1e-7 + 'e+' + 0) / 1).toFixed(0) // gives 'NaN' Actually it's pretty logic: 1e-7 + 'e+' + 0 === '1e-7e+0' // the string on the right hand side passed to Math.round results in NaN |
I see, that there is a fix already for that issue, but build on Travis has been failed. @RaviDasari, any progress on that? |
@JasonRammoray , Yes. I fixed an extra comma in test case which is failing the build and it was green again. But I didn't see any updates from the authors. I am still waiting and I see so many PRs (from a very long time) in queue waiting to be merged by author. |
@RaviDasari , perhaps, it make sense to indicate authors who shall review your request. |
@JasonRammoray , I am not able to add reviewers because of author settings! I see many PRs(all that I checked just now) don't have reviewers assigned. Perhaps only @adamwdraper can add reviewers to delegate work. Nevertheless, @adamwdraper should be notified because he is the author and we mentioned him many times. |
@RaviDasari, ok got it. |
Any news? |
Nope.
On Thu, Sep 21, 2017 at 7:03 AM Michael A. Volz (Flynn) < ***@***.***> wrote:
Any news?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#512 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AF2xypOVN4dKkO7GhrxEvz8kHSXN3vSFks5skkKGgaJpZM4NlgT_>
.
--
Thanks & Regards
Ravi Babu Dasari
|
I'm not sure how we could get in touch with @adamwdraper to add more collaborators to the project but I tweeted him... |
Hmm.
…On Mon, Dec 4, 2017 at 12:52 AM Niles Turner ***@***.***> wrote:
I'm not sure how we could get in touch with @adamwdraper
<https://github.com/adamwdraper> to add more collaborators to the project
but I tweeted him...
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#512 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AF2xyhUhinikCrDCXtg8DB8s1G-VnJ8Uks5s84h_gaJpZM4NlgT_>
.
|
Any news on this? |
No news... It seems like either find another way to get in contact with @adamwdraper or find someone with who has the capacity to fork the repository and start a new repo / package. |
Has @adamwdraper died, or been ignoring us? What's the best thing to do now? I use the NPM package. |
@tab00, I wouldn't make such guesses with respect to the author since anything could happen and we don't know that for sure.
|
This issue has been bugging me for too long now. numbro seems to handle this fine, so I will probably switch to that instead. |
…tring is in exponential format). Optimize toFixed when dealing with int values. Removed some dead vars. Related to adamwdraper#512, adamwdraper#543, adamwdraper#545, adamwdraper#596
Why is this issue still open? I am switching to "2.0.4" for now, but is this repo still active? |
This library should be marked as no longer active/maintained since the last release was in 2017 and all the bugs are ignored. I would recommend using another library which is still maintained. |
@SourceCipher Do you have any recommend? |
We have replaced with the https://numbrojs.com library most of our code base |
Numbro also has a fatal flaw, namely rounding to integers does not work |
numeral return NaN in version 2.0.6 if format negative exponential is beyond 7 points.
numeral(1e-7).format('0,0.00')
version 2.0.4 numeral returns 0.00
version 2.0.6 numeral return NaN
The text was updated successfully, but these errors were encountered: