![]() Property Pounds : integer read GetPounds write SetPounds //Weight in pounds Property Stones : integer read GetStones write SetStones //Weight in stones, fraction part ignored Property Weight : double read FWeight write SetWeight //Weight in stones.pounds format Procedure SetWeight(const Value: double) Procedure SetStones(const Value: integer) Procedure SetPounds(const Value: integer) Or you COULD do something like this :-) unit PoundsAndStones Either integers or floating point could make sense. The other obvious way to store such data is as pounds. Add 10 lots of that to get 100/14, and well, I'm sure you get my drift! But it's clear that the actual value is 100 pounds, or 7 stone two pounds.īut if you take 10 pounds and feed it into: weight := stones + pounds/14.0 Add up 10 lots of that and you have a weight of 1.0. To see that, suppose these 10 people, and they all weigh zero stones, 10 pounds. It makes sense to do that with true floating point representation, but not with your representation. For example, suppose you have measured weights of 10 people and want to know the total. ![]() ![]() Imagine what happens when weight=9.99, for example.ĭoing it this way makes arithmetic on the floating point values more sensible. Unfortunately you still need to do the div/mod shuffle. In the other direction you would do it like this: stones := Trunc(weight) If you are going to use a floating point format you should do it like this: weight := stones + pounds/14.0 That's because it's a very poor way to store weight. I'd be very surprised if you found this code anywhere in a general purpose library. The validity checks for values of pounds greater than 14 are easy to deal with. With these functions you can readily do the rest. In the other direction you do: weight := stones + pounds/100.0 Then use Round to get it in integer form: pounds := Round(100*Frac(weight)) Īnd for stones it's just Trunc: stones := Trunc(weight) I thought of checking the pounds part and if the value > 0.13 then I increment the stones, but then I am not sure how best to do this especially, if the value could be something like 13.76 then I wouldn't know what to change the stones and pounds into (this is where I start to confuse myself).įor pounds you get the fractional part with Frac(weight) and then multiply by 100. If not I would be really interested to see an answer that shows the logic or method of approach to solving this. Is there a built-in math function that can correctly format/round stones and pounds correctly? 00 - so with that in mind, from the above sample two of those values are incorrect: 13 should increase the stones value by 1 and lower the pounds value starting back from. There are only 14 pounds in a stone, so any value entered that is over. To better understand, first look at these sample values, they are represented as Stones and lbs: The record data is edited at runtime and I need to know a way of formatting the entered data correctly. The chart is populated by data from a record, for weight the data type is Double. I have a chart used to display weight in Stones and Pounds (lbs).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |