Page 1 of 1

Cookery weights and measures conversion

Posted: Thu Oct 09, 2008 8:40 am
by mattcooper
Hi all,

I'm working on a little recipe app for a client and she wants it to be able to convert metric weights and measures to imperial (and vice-versa), as one might expect. However, in cookery it appears that accuracy is not an issue; rounding is more important, but there are no hard-and-fast rules that I can work with.

For example, converting milliliters to fluid ounces is relatively consistent up to about 16fl oz, and then the direct relationship is dumped in favour of saying "16fl oz == 500ml" instead of whatever the accurate metric value might happen to be.

I'm possibly faced with writing a long, arduous class to deal with this so I thought I would ask you guys if you know of anything that already exists that might be a solution? Have check PEAR libs and no dice there.

Fingers crossed then... :D

Re: Cookery weights and measures conversion

Posted: Thu Oct 09, 2008 8:45 am
by aceconcepts
I may be missing the point but can't you make use of floor() and ceil() PHP functions.

Re: Cookery weights and measures conversion

Posted: Thu Oct 09, 2008 8:49 am
by mattcooper
No, I'm afraid not, it's not as simple as that :D It would be OK if there was consistency in the way things are rounded, but there isn't.

Re: Cookery weights and measures conversion

Posted: Thu Oct 09, 2008 8:52 am
by VladSun
Can you give us examples where round/fllor/ceil are not going to result properly, so we could help you?

Re: Cookery weights and measures conversion

Posted: Thu Oct 09, 2008 9:00 am
by mattcooper
Not without recreating a large spreadsheet here. It's quite a specific class I'm looking for and I'm not asking for a solution from you chaps :)

The question is "does anyone know of a PHP class that tackles cookery-specific weights and measures conversion?"