--
You received this message because you are subscribed to the Google Groups "AtlantaPHP Discussions and Job Postings" group.
To post to this group, send email to atlan...@googlegroups.com.
To unsubscribe from this group, send email to atlantaphp+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/atlantaphp?hl=en.
Rob Peck
r...@robpeck.com
http://www.robpeck.com
I have a suggestion which might strike you as a bit odd, but it would perfectly fit all possible scenarios.
Store the length as a ‘whole number multiple’ of the smallest measurable interval. For instance, if pipe diameters are measured in 1/16th of an inch, the smallest unit would be 1 u (just making that up that unit ‘u’ for convenience).
1 inch would be 16 u
2 1/4 inch would be 2 * 16 + 1/4 * 16 = 36 u
The point here is that you’re always storing the units as an integer, never as a fraction (which would be prone to rounding off errors). All your calculations would never give you problems, although when representing to the user, you’ll need to “convert” them into human-readable / more-intuitive forms.
Incidentally, this approach is followed in all financial transactions when “money” is stored in integer units of ‘pennies’ (technically, its stored in smaller units of those).