-
Notifications
You must be signed in to change notification settings - Fork 2
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
Precision of entered and displayed units #78
Comments
I'm a fan of saving numbers as rationals because of problems like this -- only converting it for display. But I guess that would take more effort to change. |
The datatypes we can choose from there are limited:
I think our best choice would be to simple increase the scale and precision of the decimals in use to make all real-life cases work. (The only downsides of using DECIMALS with high precision: Negative impact on db size and performance) Then we need to identify those places where rounding still might occur and flash apt warnings when users try to enter numbers that will cause "weird" rounding behavior. Maybe you have some insights on this @yksflip ? |
We'd only need a pair of (big enough) integers, but the problem remains. Some (probably stupid) ideas:
|
No, I think, there'd be instances where at least the dividend could have decimal points (Simply if the user enters them into a field that has to be divided before storing it to the db). But that is no really the issue.
Yes, and even if we could use them, UDTs would still be slow in SQL calculations (like
Yes, I'm afraid that would make it even (slightly) slower than just storing dividend and divisor as two columns directly and solve none of the problems.
Even if that would help (which I believe it doesn't - see above), it would add a technology barrier, which I think everyone would like to avoid. (Right now, foodsoft may be optimized and best tested on MariaDB, but should in theory function on all current popular relational DBs supported by rails.) So, since there were no other feasible suggestions so far, I'll "fix" this by increasing |
Re-raising a logical issue:
We've had a similar problem before and I thought it to be solved, but the following logical issue just occurred to me again:
Using the received form for the oranges from our current small.en.seeds (
supplier_order_unit: "Piece (12 kg)", group_order_unit: kg
):When receiving an amount of 4 kg, the stored value will be displayed as 3.996 kg. That happens as the
units_received
are stored insupplier_order_unit
(to be directly and safely comparable withunits_to_order
which is obviously stored in the same unit) and 4 / 12 is 0.3333333... but only 3 decimals are stored. So when trying to convert it back for re-editing/display 0.333 * 12 turns out to be 3.996.The quick fix would be to simply increase precision (to 6 e.g.), but obviously, if ratios are to high, the problem will still occur.
This is related to, but I believe not quite the same, as #72.
The text was updated successfully, but these errors were encountered: