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

Calculate prices in cent integers #52

Open
lukasdenk opened this issue Nov 12, 2021 · 5 comments
Open

Calculate prices in cent integers #52

lukasdenk opened this issue Nov 12, 2021 · 5 comments
Labels
enhancement New feature or request
Milestone

Comments

@lukasdenk
Copy link

Since floats are mathmatically uncountable, Python does not always calculate them correctly. This problem occurs, e.g. with some prices in the FMIParser.
E.g.:

Python Console
4.6+0.8
5.3999999999999995

Solution:

Calculate prices in cents. Then format them to a string containing the euro-format.

@lukasdenk lukasdenk changed the title Calculate prices in cent integers, not in float euros Calculate prices in cent integers Nov 12, 2021
@COM8
Copy link
Member

COM8 commented Nov 13, 2021

This is a breaking change. Although I definitely see the need for this "fix" I would like to postpone it for an eventual V3 of the API.

How would you generate a string prince in python, since you probably will have the same problem, like you have shown here.

@COM8 COM8 added the enhancement New feature or request label Nov 13, 2021
@COM8 COM8 added this to the V3 API milestone Nov 13, 2021
@lukasdenk
Copy link
Author

@COM8: I would calculate the prices in cent in a variable like priceInCents and make the price available as a @property. The property then always calculates the price from priceInCents.
Until v3, we could also make this property return a float.

@COM8
Copy link
Member

COM8 commented Nov 16, 2021

Yes, this would be an option.

@Philipp000
Copy link

Calculating the prices in integers of cents are a valid option.
However, i think we still should return numbers for the prices instead of already formatted strings.
As we always have at most two decimals for prices, we could use the round function from Python, to eliminate the rounding errors.

Even though, strings or numbers for prices probably wouldn't make a big difference at the moment, I still think for a good API, we shouldn't provide formatted values.

@xdevs23
Copy link

xdevs23 commented Jan 9, 2022

Price formatting should be done in frontend by a library specifically made for this purpose so changing this to cents in v3 is probably the best option

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

No branches or pull requests

4 participants