# [Lazarus] procedure FloatToDecimal

Reenen Laurie rlaurie at gmail.com
Mon Sep 1 07:29:39 CEST 2008

```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.
>
>
> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20080901/efb0f611/attachment-0006.html>
```