Cookery weights and measures conversion

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mattcooper
Forum Contributor
Posts: 210
Joined: Thu Mar 17, 2005 5:51 am
Location: London, UK

Cookery weights and measures conversion

Post 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
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Cookery weights and measures conversion

Post by aceconcepts »

I may be missing the point but can't you make use of floor() and ceil() PHP functions.
User avatar
mattcooper
Forum Contributor
Posts: 210
Joined: Thu Mar 17, 2005 5:51 am
Location: London, UK

Re: Cookery weights and measures conversion

Post 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.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Cookery weights and measures conversion

Post by VladSun »

Can you give us examples where round/fllor/ceil are not going to result properly, so we could help you?
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
mattcooper
Forum Contributor
Posts: 210
Joined: Thu Mar 17, 2005 5:51 am
Location: London, UK

Re: Cookery weights and measures conversion

Post 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?"
Post Reply