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

Update asset_object::amount_to_string implementation #1012

Merged
merged 4 commits into from
Jun 21, 2018

Conversation

abitmore
Copy link
Member

@abitmore abitmore commented Jun 2, 2018

Code copied from amount_from_string.

By the way, what if amount is negative?

Copy link
Contributor

@jmjatlanta jmjatlanta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some surprising results. Some are due to the hack for the expected result, but the negative numbers are troubling. I didn't spend a lot of time debugging, but hopefully this will help.

https://gist.github.com/jmjatlanta/9c17db807cca638ef9158467592b8bf0

@abitmore
Copy link
Member Author

abitmore commented Jun 6, 2018

@jmjatlanta I'd say don't use pow in test cases since it will introduce float points.

@jmjatlanta
Copy link
Contributor

jmjatlanta commented Jun 18, 2018

Please take a look at PR #1071. I fixed the POW and am just using hardcoded strings. Negative numbers still do not look right.

Update: Made a modification to asset_object::amount_to_string to handle negative numbers. Take a look. Could this method be passed a const?

Update2: switched to const reference.

@abitmore
Copy link
Member Author

Thank you @jmjatlanta. It turns out that there were 2 bugs in the code.

  • -12345 % 100 = -45, so fc::to_string(scaled_precision.value + decimals).erase(0,1) = to_string(100 + (-45)).erase(0,1) = to_string(55).erase(0,1) = "5", so final result is "-123.5"
  • -12345 / 100000 = 0, so string result = fc::to_string(amount.value / scaled_precision.value) = "0", then after result += "." + ... the final result looks like a positive number.

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

Successfully merging this pull request may close these issues.

3 participants