Posted on 2003-03-04
I have a program with the following code...
procedure TProfile.SetProfileLdg(Length: Single; Precision: Integer);
// Sets the Length of the Profile, according to the precision (no. of
// decimal places) given as the second parameter.
CASE Precision of
0: Self.Length := Round(Length);
1: Self.Length := SimpleRoundTo(Length, -1);
2: Self.Length := SimpleRoundTo(Length, -2);
After reading delphi's help on 'SimpleRoundTo', I expected a call with e.g. Profile.SetProfileLdg(100.123456, 1) to return a result of 100.1, but instead I get maybe 100.1000001234 or something similar. Where am I going wrong? Is there another, more suitable, approach to getting a real number rounded to 1 or 2 decimal places?
Any help greatly appreciated.