Total : wrong number of decimals after soustraction of total

DomiDomi Belgium
edited 9:44AM in FastReport .NET
Hi,

I have 2 columns from a ms access datatase (the fields are 'numbers' with 2 decimals places),
I make a summation of these columns and I substract one total value from the other;
althought the difference must be zero, it gives me 0.00114250 ....

how is this possible and, most over, how to fix it ?
thanks in advance,
Domi.

fr1.jpg 103.5K

Comments

  • edited March 2018
    1. are you calling msaccess db from fastreport directly? or push data from .net code to fastreport?
    2. what datatype you're using? float, double, decimal? float is less precision
    3. make sure that you've 2 decimal places in the msaccess data, what kind of field type?
  • DomiDomi Belgium
    edited 9:44AM
    Hi ipong,

    ?°) I'm calling msacces directly from fastreport (except that I pass the connection string thru the 'parameters')
    ?°) i'm using Number ('double' with 2 decimal places)

    here is a screenshot of the msaccess designer for the fields.

    thanks for trying to help me,
    sincerly,
    Domi.

    fr2.jpg 116.1K
  • edited March 2018
    do not use floating point (float and double datatypes) for accounting records!

    msaccess => use currency datatype
    mssql => use money datatype


    why?
    https://stackoverflow.com/questions/2144627...access-database

    http://csharpindepth.com/Articles/General/FloatingPoint.aspx

    http://www.extremeoptimization.com/resourc...AndFormats.aspx
  • DomiDomi Belgium
    edited March 2018
    Thanks for your links but that doesn't work ! I have replaced all the Double with Currency (in my ms database) and I get the same result :

  • edited 9:44AM
    have you refreshed datasource? check your frx file with notepad:

    make sure debit and credit with 'System.Decimal' datatype
        <MsAccessDataConnection Name="Connection" ConnectionString="rijcmlqoDWEBRlB24atBGpA/h9/NbwdWKfjN0xexwR499WDO0y7IJqtWaFegHY0F1Ho9V3Fl2kdv07imQ17CfhEkp1BNgqLT3fvMk7zv9YAiakHxLY=">
          <TableDataSource Name="tbUser" DataType="System.Int32" Enabled="true" TableName="tbUser">
            <Column Name="id" DataType="System.Int32"/>
            <Column Name="name" DataType="System.String"/>
            <Column Name="password" DataType="System.String"/>
            <Column Name="Debit" DataType="System.Decimal"/>
            <Column Name="Credit" DataType="System.Decimal"/>
          </TableDataSource>
        </MsAccessDataConnection>
    
  • DomiDomi Belgium
    edited March 2018
    Hi,

    yes a refresh was made, removed completely the DB and add it back to be sure

    here is the def :
          <TableDataSource Name="Lign" DataType="System.Int32" Enabled="true" TableName="Lign">
            <Column Name="CleLIGN" DataType="System.Int32"/>
            <Column Name="MVTS" DataType="System.Int32"/>
            <Column Name="NUMC" DataType="System.String"/>
            <Column Name="LIBE" DataType="System.String"/>
            <Column Name="DEBI" DataType="System.Decimal"/>
            <Column Name="CRED" DataType="System.Decimal"/>
    ...
    
        <Total Name="TotalDebit" Expression="Lign.DEBI" Evaluator="Data1"/>
        <Total Name="TotalCredit" Expression="Lign.CRED" Evaluator="Data1"/>
    ...
    
          <GroupFooterBand Name="GroupFooter1" Top="138.85" Width="718.2" Height="37.8">
            <TextObject Name="Text17" Left="481.95" Top="9.45" Width="217.35" Height="18.9" Text="Solde : [[TotalDebit]-[TotalCredit]]" />
          </GroupFooterBand>
    


    BUT


    I have added 'Format="Currency"' in the xml :
            <TextObject Name="Text17" Left="481.95" Top="9.45" Width="217.35" Height="18.9" Text="Solde : [[TotalDebit]-[TotalCredit]]" Format="Currency" >
    

    and the format is like expected which is strange because the TextObject doesn't contain only numbers but also text : "Solde : TotalDebit]-[TotalCredit"

  • edited March 2018
    have you solved 0.0012999..... ? if not, i think there is something wrong in your data
    you may check with creating 'running sum' with code.

    use currency formatting only if solved
  • DomiDomi Belgium
    edited 9:44AM
    As you can see in my last post/printscreen, the display is now correct (2 decimals) after added Format="Currency" in the field containing the substraction but I don't know if it's the right way or not to solve this

    Domi.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.