For pounds, you get the fractional part with Frac(weight) , and then multiply by 100. Then use Round to get it in integer form:
pounds := Round(100*Frac(weight));
And for stones, it's just Trunc :
stones := Trunc(weight);
In the other direction:
weight := stones + pounds/100.0;
With these features, you can easily do the rest. The validity of checking pounds is greater than 14, which are easy to handle. For instance:
stones := Trunc(weight); pounds := Round(100*Frac(weight)); stones := stones + pounds div 14; pounds := pounds mod 14;
I would be very surprised if you could find this code anywhere in the general purpose library. This is because it is a very poor way to store weight. If you are going to use a floating point format, you should do it like this:
weight := stones + pounds/14.0;
In the other direction, you will do it as follows:
stones := Trunc(weight); pounds := Round(14*Frac(weight)); stones := stones + pounds div 14; pounds := pounds mod 14;
Unfortunately, you still need to shuffle the div / mod. Imagine what happens when weight=9.99 , for example.
Performing this method makes arithmetic of floating point values ββmore reasonable. For example, suppose you measure 10 people and want to know the total. It makes sense to do this with a true floating point representation, but not with your representation.
To see this, suppose these 10 people, and they all weigh zero stones, 10 pounds. Very small people I know. But you would call it 0.1. Add 10 lots, and the weight is 1.0. But it is clear that the actual value is 100 pounds, or 7 stone two pounds.
But if you take 10 pounds and feed them:
weight := stones + pounds/14.0;
then you will find the weight value 10/14. Add 10 lots to get 100/14, and well, I'm sure you will get my drift!
Another obvious way to store such data is in pounds. Either integers or a floating point can make sense.