Procedure FloatToDecimal(Out Result: TFloatRec; Value: Extended; Precision,
Decimals : integer);
The Precision, and Decimals work together to ensure the rounding etc.
So lets say you want to have float to decimal, and have 5 "digits"... And you do it on a value of 2 then the result will be
2.00000
If you only want a precision 2 but want decimals 5, and run it for pi, you will get
3.14000
So general rule is to have your precision higher than your digits, and you'll have good "rounding".
Hmmm... My test program shows some funnies:
procedure TForm1.FormDblClick ( Sender : TObject ) ;
var t : TFloatRec;
begin
FloatToDecimal(t,pi,5,3);
ShowMessage(inttostr(t.Exponent)+'.'+t.Digits);
end;
Shows 3.1432 -- not 3.143 as expected...
FloatToDecimal(t,pi,2,6);
Showed, 3.14
(not 3.140000) as I expected...
On Sat, Aug 30, 2008 at 4:19 AM, H?ctor Fiandor Rosario <
Show quoted text 30 lines
wrote:
Dear sirs:
I need to convert a Float to a number with two decimal places in a Lazarus
Project for Windows..
I am thinking to use the following procedure:
Procedure FloatToDecimal(Out Result: TFloatRec; Value: Extended; Precision,
Decimals : integer);
begin
FloatToDecimal(Result,Value,fvExtended,Precision,Decimals);
end;
but I dont know what to write in some of the arguments.
Thanks in advance for your help,
yours truly,
Ing. H?ctor F. Fiandor
_______________________________________________
Lazarus mailing list
http://www.lazarus.freepascal.org/mailman/listinfo/lazarus