-
Notifications
You must be signed in to change notification settings - Fork 92
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
Fraction sometime get converted, sometime not. Don't want them converted #2576
Comments
This comes from the recalculation algorithm. What would be valid fractional values? How about 2/3? 7/8? 22/15? 2135/52351? At some point we need to make a cut and either round or go with decimals. If you have a good suggestion on how to handle this, then feel free to state that. We can then see if this is implementable. |
There's a way to save fraction reel value in database. There's surely already library available to do that. I used to do it in native PHP back in 2001 so surely there's something today that's able to do that, specially with all the other website that are able to. Maybe already save more then 2 decimal. Save like 6, since nobody will ever require 6 decimal, you check 5 decimal and if it match, it's a fraction. That would be a way of doing it, not the prettiest. |
I think we misunderstand. Apart from the fact that the values are not stored ATM in the database, we are not storing the numeric value at all. We are just storing a list of strings like The problem comes into play, once we have the recalculation algorithm in place. The user in the frontend simply can configure a scaling factor for all ingredients.
The last can cause trouble: Wht if the user requests a factor of 12.042? Do you really want to print |
I would already say don't convert any fraction. It's very easy to scale fraction, there's a lot of math function ready to do that. And if it's not a fraction, let it not a fraction. What you could do is put the quantity in a separate box. If none is present, don't scale cause its a string like pinch. This way you don't have to search for the number. That's usually how I see it in other recipe program. |
OK, let's separate implementation from expected behavior. First, we need to define the desired behavior. How to implement this can be addressed later. I just wanted to give you insight why some claims of yours are plainly useless as these were based on wrong assumptions. Nevertheless, what do you mean by "not convert any fractions"?
If you have more ideas, feel free to add them. |
Self-note: One can use chain-fractions eventually for approximations. |
Fraction convert isn't hard to do. You can do it with 3 simple mathematical expression. Let's say you have 3/4 and you want 3 times that? You want 3 * 3/4 which give 9/4 (you can extract the numerator and denominator quite easily). Then, you do 9 / 4 and keep only integer part of 2,25 which is 2 (function already exist for that) and then you use mod function with 9 mod 4 = 1. Result? 2 1/4. That's how you normally convert fraction without needing to caculate. After, if you want to reduce the fraction to the smallest possible like 2/4 = 1/2, there's multiple mathematic way to do so but I'm pretty sure there's already math library available to do all of that. If someone enter 501/1000, it's not 1/2, it's 1/1000 more then 1/2. Don't forget you are dealing with recipe, you don't see stuff like that in recipe. If someone try to go this way, just don't support it, it's useless to try to do everything for a recipe. Already, there's nothing in real life that will give you the ability to measure 501/1000. Recipe come in /2, /3, /4 and /8. Sometime you see the other one, but there's not even tools to measure these (at least for home user). You could go with the GCF method using only 2,3,4 and 8, which imply a maximum of 8 calculation per fraction (but using some mathematic logic, you can have it do most of the time only 1 step). I would never convert a fraction to a digital representation. At worst, don't touch it. |
Description
When adding ingredient, sometime fraction are required like 2/3 cup of water or 1/4 tablespoon of salt. The fraction 1/4 stay as 1/4 once saved but the 2/3 get transformed to 0.67. I want the fraction to stay and not have the decimal number (in fact, I want what I enter to stay). It seems to work for 1/2, 1/4, 3/4 but not 1/3, 2/3.
Also, when adding quantity, don't show 0/1
Reproduction
Steps to reproduce the behavior:
Expected behavior
A clear and concise description of what you expected to happen.
Actual behavior
Should be 2/3 not 0.67
After changing quantity, now displaying a 0/1:
Screenshots
Recipe edit:
Browser
Edge
Versions
Nextcloud server version: 30.0.2
Cookbook version: 0.11.2
Database system: PostgreSQL
The text was updated successfully, but these errors were encountered: