## Writing Cookbook - how to enter fractions

cforput
Registered Member
Posts
5
Karma
0

### Writing Cookbook - how to enter fractions

Thu Nov 22, 2012 2:54 pm
I'm going to write myself a little cookbook db and was wondering what the best way to enter fractions would be. Eventually, I want to be able to scale recipes so I can't enter it as text (or at least I don't think I can) because I wouldn't be able to do any math on the value. Any ideas?
scummos
KDE Developer
Posts
774
Karma
5
OS

### Re: Writing Cookbook - how to enter fractions

Thu Nov 22, 2012 4:46 pm
You could use two integers, one for nominator and one for demoninator. That makes math and display quite easy, doesn't it?

Greetings

jstaniek
Moderator
Posts
587
Karma
1
OS

### Re: Writing Cookbook - how to enter fractions

Thu Nov 22, 2012 11:32 pm
Perhaps you could use 'Floating Point Number' data type for the column?

We're currently not supporting decimal data type in Kexi, which would be better choice than the Floating Poing Number because the latter causes inexactness.

Best regards,
Jarosław Staniek

Kexi - Visual DB Apps Builder
Do you like Kexi? Consider donating to boost its development!
scummos
KDE Developer
Posts
774
Karma
5
OS

### Re: Writing Cookbook - how to enter fractions

Thu Nov 22, 2012 11:53 pm
Using float will probably make it difficult to display the numbers as fractions in the recipe -- unless you want to write some fancy approximate-float-by-small-fraction algorithm

Greetings

jstaniek
Moderator
Posts
587
Karma
1
OS

### Re: Writing Cookbook - how to enter fractions

Fri Nov 23, 2012 11:59 am
@scummos: of course we always need a place to keep a unit (kg, spoons...). It's more needed if searching by ingredients/quantities is expected.

Floating point numbers are acceptable with rounding used upon displaying. Decimal type is ideal solution though.

Please note that we have no place to currently enter complex expressions in the form boxes; some arithmetic can be entered in SQL queries although forms based on queries are read-only at the moment.

Scriptability of database layer and GUI would solve the problem, data could be broked down in many columns when needed, e.g. like you proposed.

Best regards,
Jarosław Staniek

Kexi - Visual DB Apps Builder
Do you like Kexi? Consider donating to boost its development!
scummos
KDE Developer
Posts
774
Karma
5
OS

### Re: Writing Cookbook - how to enter fractions

Fri Nov 23, 2012 1:14 pm
Okay, I see.

Of course floating point numbers have the needed accuracy, but they will make it difficult to display "half a cup" or "4/5 liters". That's what I was hinting at.

Greetings,
Sven

jstaniek
Moderator
Posts
587
Karma
1
OS

### Re: Writing Cookbook - how to enter fractions

Fri Nov 23, 2012 2:20 pm
scummos wrote:"half a cup"

Symbolically, using two columns (value, unit) it could be:

(0.5, "cup")

scummos wrote:"4/5 liters"

(0.8, "l")

Best regards,
Jarosław Staniek

Kexi - Visual DB Apps Builder
Do you like Kexi? Consider donating to boost its development!
cforput
Registered Member
Posts
5
Karma
0

### Re: Writing Cookbook - how to enter fractions

Fri Nov 23, 2012 5:33 pm
Scummons' first post got me thinking. Could I do this:

Use a text box to enter the fraction then use "left" and "right" fucntions to peel off the values, convert text to numbers, do the math and then store that value in a field that is not displayed?

Well, at least it has give me some ideas. Thanks all.
scummos
KDE Developer
Posts
774
Karma
5
OS

### Re: Writing Cookbook - how to enter fractions

Fri Nov 23, 2012 11:46 pm
jstaniek wrote:
scummos wrote:"half a cup"

Symbolically, using two columns (value, unit) it could be:

(0.5, "cup")

scummos wrote:"4/5 liters"

(0.8, "l")

Yeah, right, but how do you know that you need to display "4/5" when the database reads "0.8"? That's what I see as an at least not entirely trivial problem.

cforput wrote:Use a text box to enter the fraction then use "left" and "right" fucntions to peel off the values, convert text to numbers, do the math and then store that value in a field that is not displayed?

That's what I meant, but I can't tell you whether it's actually reasonably possible.

Greetings

littauer
Registered Member
Posts
8
Karma
0

### Re: Writing Cookbook - how to enter fractions

Sat Nov 24, 2012 8:54 pm
A little knowledge of the problem domain may come in handy.

In general, cooking comes in 2 flavors: savory and pastry (sweets, breads and the like); odd cooking (brewing e.g.) will often be like pastry.

Pastry is far more precise than savory and is generally done by weight rather than volume. For scaling purposes professional pastry cooks use "baker's percentages". (Google is your friend.) If a pastry cook is to use your database, being able to work in weights and/or BP will be valuable.

Savory cooks tend to round up and down a lot more. Many savory recipes still work if values are off by as much as 30% even though that's extreme.

A scale-up that resulted in 4 cups plus 1.375 teaspoon will immediately be rounded down to 4 cups by all but the newest savory cooks unless they know WHY that extra teaspoon is required. You'll need a way to know whether to round and by how much. Being overprecise will only annoy your user.

Fractional values are almost always in fourths, halves and sometimes thirds. ETA: Oh yes, 16th unless working metric

Just to make it messier, people who cook both will vary the technique by which it is: when I make bread, I weigh. When I make stew I eyeball it.

Hope this helps,

Tom

## Who is online

Registered users: AgeOfAsparagus, andreas_k, apol, Baidu [Spider], Bing [Bot], bobthebuilder, davidemme, drosca, einar, Exabot [Bot], Google [Bot], google01103, hein, jaimesilva, jowlo, koriun, louis94, lukas.tinkl, manuelmuzzurru, mbrugger, metzman, mgraesslin, MSNbot Media, nbelavic, nylnook, paulus3005, pedromartinez, pedrorodriguez, sdh, spleen, Steve Guilford, vpinon, Yahoo [Bot]