-
Notifications
You must be signed in to change notification settings - Fork 6
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
Switch prices to decimal representation #1
Comments
Correct me if I'm wrong, but this would also have to be done, essentially, through |
Actually, I did not yet thought this through in any way yet. I only noticed this when I was writing the find_cheapest_server_type example, where I parsed the priced into Changing the implementation after generation would be one way to go, another would probably be starting to provide manually implemented helper functions or structs that handle the conversion. There are probably other ways as well. |
Would it make sense to use u64 and cents instead to avoid floating point issues? |
Hi, Max (the maintainer of https://github.com/MaximilianKoestler/hcloud-openapi) here. Going for cents might be tempting but:
|
@kpcyrd I'm actually not quite sure what floating point issues you are referring to. Currently, the API just forwards Hetzner's representation of prices as a string type. For the example I mentioned earlier, floating point errors are not really an issue, because it is just about sorting by price (which would not work for strings). But I would agree with you that using floating point types on the API for representing currency would be a bad idea. And @MaximilianKoestler is totally right, in fact, the hourly prices for most of the servers are already more precise than one cent, as you can see on the cx11 server type:
However, while the strings are the exact representation, they are not really useful for any sort of calculation. This is where my initial thought of providing something more convenient (but in any case still correct) was coming from. Writing this, I would even consider it more likely that users who are unaware of the "floating point numbers are not a good idea for currency" issue will convert the prices to floating point for calculations when they are only available as strings. |
We could opt to wrap usage of |
Currently, prices are repesented as
String
type, e.g.:hcloud-rust/src/models/price.rs
Lines 16 to 23 in 52da68e
Using decimal representation (e.g. rust_decimal) would be more convenient for calculations.
The text was updated successfully, but these errors were encountered: