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

Use BigDecimal instead of double #44

Closed
denis-konovalyenko opened this issue Feb 24, 2019 · 13 comments
Closed

Use BigDecimal instead of double #44

denis-konovalyenko opened this issue Feb 24, 2019 · 13 comments

Comments

@denis-konovalyenko
Copy link
Contributor

There are 2 methods of the Wallet interface, which uses double type: balance and pay.

Representing money as a double or float will probably look good at first as the software rounds off the tiny errors, but as you perform more additions, subtractions, multiplications and divisions on inexact numbers, errors will compound and you'll end up with values that are visibly not accurate. This makes floats and doubles inadequate for dealing with money, where perfect accuracy for multiples of base 10 powers is required.

A solution that works in just about any language is to use integers instead, and count cents. For instance, 1025 would be $10.25. Several languages also have built-in types to deal with money. Among others, Java has the BigDecimal class, and C# has the decimal type.

For more details please refer to this resource.

@0crat
Copy link
Collaborator

0crat commented Feb 24, 2019

@amihaiemil/z please, pay attention to this issue

@denis-konovalyenko
Copy link
Contributor Author

@amihaiemil , as an alternative, I am tending to like this more and more, we can easily go with String types for balance and pay methods and leave all type conversion/parsing for the upper/user layer:

    String balance();
    void pay(
        final String keygap, final String user,
        final String amount, final String details
    );

What do you think?

@amihaiemil
Copy link
Owner

@denis-konovalyenko looks good! We do it with Strings and let folks take care of it, it's safer :)

@0crat 0crat removed their assignment Feb 25, 2019
@0crat 0crat added the scope label Feb 25, 2019
@0crat
Copy link
Collaborator

0crat commented Feb 25, 2019

Job #44 is now in scope, role is DEV

@0crat
Copy link
Collaborator

0crat commented Feb 25, 2019

Bug was reported, see §29: +15 point(s) just awarded to @denis-konovalyenko/z

@0crat
Copy link
Collaborator

0crat commented Feb 27, 2019

The job #44 assigned to @ammaratef45/z, here is why; the budget is 30 minutes, see §4; please, read §8 and §9; if the task is not clear, read this and this; there will be no monetary reward for this job

ammaratef45 pushed a commit to ammaratef45/zold-java-client that referenced this issue Feb 27, 2019
ammaratef45 pushed a commit to ammaratef45/zold-java-client that referenced this issue Feb 28, 2019
@ammaratef45
Copy link
Collaborator

@denis-konovalyenko Is it fine now?

@denis-konovalyenko
Copy link
Contributor Author

denis-konovalyenko commented Feb 28, 2019

@ammaratef45 , what do you mean? As far as the pull request has been merged, 0crat should put the issue out of scope and close it. Maybe, it is too lazy today and it will take it a bit of time to accomplish that. :)

@ammaratef45
Copy link
Collaborator

@denis-konovalyenko Hmmm, usually zerocrat doesn't close issues (reporter close it or PDD if it was a puzzle)
Am I missing something?

@denis-konovalyenko
Copy link
Contributor Author

@amihaiemil , ah, no problem. I think this is not clearly stated in the policy (or I missed that).

@0crat
Copy link
Collaborator

0crat commented Feb 28, 2019

Job was finished in 31 hours, bonus for fast delivery is possible (see §36)

@0crat 0crat removed the scope label Feb 28, 2019
@0crat
Copy link
Collaborator

0crat commented Feb 28, 2019

The job #44 is now out of scope

@0crat
Copy link
Collaborator

0crat commented Feb 28, 2019

Order was finished: +35 point(s) just awarded to @ammaratef45/z

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

4 participants