Re: decimal problem
From: Jose Perez (jomperez_at_optonline.net)
Date: 01/07/04
- Next message: Jamie: "Re: UNICOWS.DLL -- ??? Very confused -- Please help"
- Previous message: Stark: "Re: A different solution.."
- In reply to: J French: "Re: decimal problem"
- Next in thread: J French: "Re: decimal problem"
- Reply: J French: "Re: decimal problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 07 Jan 2004 17:51:20 GMT
"J French" <erewhon@nowhere.com> wrote in message
news:3ffbff00.16867650@news.btclick.com...
> On Wed, 7 Jan 2004 12:23:40 +0100, "Bert Prins" <prinsoft@hotmail.com>
> wrote:
>
> >Hello.
> >
> >First: the best wishes for 2004 to all of you.
> >
> >I have a problem with decimals.
> >I have two variables of the type Double. During the program the first
> >variable (fBtw) has the value 1724.725 and the second variable (fBruto)
> >10802.225. Then I converts both variables to strings with Format('%.2f',
> >variable):
> >sfBtw := Format('%.2f', [fBtw]); // -> 1724.72
> >sfBruto := Format('%.2f', [fBruto]); // -> 10802.23
> >
> >Why, o why converts Format .725 to .72 and .225 to .23 ????? I tried it
> >under WinNT and Win2000 with the same result.
> >Is there a better way to convert a double with more than 2 decimals to a
> >double with 2 decimals?
>
> I think you will find that 1724.725 is actually 1724.724999999999
>
> The Double format uses the IEEE convention
> - which has its 'features'
>
> See the FAQ for more info :-
>
> http://www.bancoems.com/CompLangPascalDelphiMisc-MiniFAQ.htm#Q3
>
I don't think that is the entire cause of the problem here. What is
happening is that the value is being rounded as it is converted to string. I
don't have access to the documentation at the moment, but if you look up the
formatting options, I believe that you will probably find that using "%.2f"
rounds the value to 2 decimal positions. To get three decimal positions, try
using "%.3f". To get the correct value, get a larger number of decimal
positions, 4 or 5, and then round to the appropriate number of decimals.
- Next message: Jamie: "Re: UNICOWS.DLL -- ??? Very confused -- Please help"
- Previous message: Stark: "Re: A different solution.."
- In reply to: J French: "Re: decimal problem"
- Next in thread: J French: "Re: decimal problem"
- Reply: J French: "Re: decimal problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|