Re: decimal problem

From: Jose Perez (jomperez_at_optonline.net)
Date: 01/07/04


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.



Relevant Pages

  • Re: Format issue ... 2 decimal places displayed?
    ... --in the format property delete everything ... Jeanette Cunningham wrote: ... to get sql of your query, open the query in design view, then select ... release the cursor and the 2008 ('without decimals') shows up in the ...
    (microsoft.public.access.forms)
  • Re: Format issue ... 2 decimal places displayed?
    ... Jeanette Cunningham wrote: ... I've finally been able to reproduce that format with 2 decimal places in a combo on the form. ... to get sql of your query, open the query in design view, then select Query | SQL view from the menu. ... release the cursor and the 2008 ('without decimals') shows up in the text ...
    (microsoft.public.access.forms)
  • Re: SUMPRODUCT formula using hours:minutes
    ... These are numbers with decimals. ... which is used to separate hours from minutes in an Excel time format. ... or can I fix it all on the payroll sheet with the macro? ...
    (microsoft.public.excel.misc)
  • Re: Page totals error in report - doesnt add correctly
    ... Thanks Marshall - it works fine now using CDblwhen I set the format ... display it on a form or report. ... and restrict the value to 2 decimals). ... All Totals text boxes properties are set to General number with 2 decimal ...
    (microsoft.public.access.reports)
  • Re: Text changes after .........
    ... -If the Value has decimals, then the Value is only in so-called U.S. format. ... data type and then use CCur to convert ... it is usual to use the TextBox's Validate event rather than its ...
    (microsoft.public.vb.general.discussion)