[Lazarus] procedure FloatToDecimal
Héctor Fiandor Rosario
hfiandor at infomed.sld.cu
Mon Sep 1 18:52:51 CEST 2008
diar Mr. Reenen Laurie:
thanks very much for your answer.
really, I think that my problem was in the TFloatRec. I see that you declare as var. I will try your suggestions.
yours,
Ing. Héctor F. Fiandor
hfiandor at infomed.sld.cu
----- Original Message -----
From: Reenen Laurie
To: General mailing list
Sent: Monday, September 01, 2008 1:29 AM
Subject: Re: [Lazarus] procedure FloatToDecimal
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 <hfiandor at infomed.sld.cu> 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
hfiandor at infomed.sld.cu
_______________________________________________
Lazarus mailing list
Lazarus at lazarus.freepascal.org
http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
--
o__
,_.>/ _
(_)_\(_)_______
...speed is good
_______________
I believe five out of four people have a problem with fractions.
------------------------------------------------------------------------------
_______________________________________________
Lazarus mailing list
Lazarus at lazarus.freepascal.org
http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
__________ Informacisn de ESET Smart Security, versisn de la base de firmas de virus 3317 (20080801) __________
ESET Smart Security ha comprobado este mensaje.
http://www.eset.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20080901/aa8c6e9b/attachment-0007.html>
More information about the Lazarus
mailing list