Skip to content
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

Returning an exponent after adding a negative value that sums to 0.0000000 #23

Open
tmbobbins opened this issue May 14, 2019 · 8 comments

Comments

@tmbobbins
Copy link

2019-05-10-160148_918x699_scrot

Appears to happen at 7 decimal places on each side (at 6 it works fine), as long as it sums to 0

@rtheunissen
Copy link
Contributor

I believe this is expected behaviour, as toString determines whether to use scientific notation based on the exponent, even for zero. The precision is preserved in the output.

You should use toFixed(), or if that is not quite what you need, we may need to look at an adjustment of string representation.

Just to be clear, was the expectation for this to return "0"?

@tmbobbins
Copy link
Author

tmbobbins commented May 14, 2019

For the first 6 decimal places toString() will return 0.000000 (6) as soon as it hits the 7th decimal place it returns an exponent, hence I would have expected it to return 0.0000000 (7), this doesn't appear to happen if the value doesn't land on 0.

Is there any way at current to make toString not return exponents if the decimal lands on a large precision number that equals 0? Or are you saying that toFixed will return the decimal representation rather than an exponent?

2019-05-14-155459_925x602_scrot

As an example the above image returns all of the decimal places rather than an exponent for any other value than 0

@rtheunissen
Copy link
Contributor

Looks like a special case to me. This issue is along the same lines as #22 so I think we should reconsider how string formatting is done. Maybe:

  • __toString / toString / (string): No exponent, no trailing zeroes.
  • toFixed: No exponent, trailing zeroes up to the number of places given.
  • toScientific or toExponentString, same as toString but always using the exponent?

@tmbobbins
Copy link
Author

aye the list looks good, consistency is the main take away.

@rtheunissen
Copy link
Contributor

My only concern is that the default toString could end up creating a very long string when precision is high, but in those cases users should just use toExponentString instead, being aware of the precision they are working with.

@rtheunissen
Copy link
Contributor

Let's roll with toString(), toFixed(int places) and toExponentString.

toString() will return a fixed representation of as many decimal places that the instance is aware of.

I think that should work.

@rtheunissen
Copy link
Contributor

See #22 (comment)

@rybakit
Copy link

rybakit commented Sep 30, 2019

@rtheunissen I've stumbled upon the same problem and saw that it had already been solved in 2.0. Is there any plan to release version 2.0 in the near future?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants