Rounding-off automatically in decimal field

Aravindh_NavisionAravindh_Navision Member Posts: 258
Hi Friends,

I have 3 decimal fields in report.

Say A, B and C where C = A + B.
For example: A = 50310.06; B = 3521.70; C = 53831.76

I am multiplying A, B and C with 1.235025 (ERV = exchange rate value) and the results are store in D,E and F respectively.

Then my answer should be: D = E + F. The problem I'm facing here is all these D, E, F fields are automatically rounding off. But I don't want those field to round-off. Instead I should get the exact value with 2 decimal places. How to proceed with it?

The code I wrote is as follows:
ERV := 1.235025;

D := ROUND((A * ERV),0.01,'<');
E := ROUND((B * ERV),0.01,'<');
F := ROUND((C * ERV),0.01,'<');
I'm getting the output as:
D := 62134.19 [50310.06 * 1.235025]
E := 4349.38 [3521.70 * 1.235025]
F := 66483.59. [53831.76 * 1.235025].

The right answer should be: 
D := 62134.18
E := 4349.38
F := 66483.56

Comments

  • lvanvugtlvanvugt Member Posts: 774
    Hi Aravindh,

    First some clarifications:

    ERV = 1.238237 or 1.235025?

    D = E + F or F = D + E?
    Luc van Vugt, fluxxus.nl
    Never stop learning
    Van Vugt's dynamiXs
    Dutch Dynamics Community
  • lvanvugtlvanvugt Member Posts: 774
    Next: this is what I am getting:
    Microsoft Dynamics NAV Classic
    D = 62.134,18
    E = 4.349,38
    F = 66.483,56
    OK
    So what's the problem?

    BTW: this is the code I have created ina codeunit:
    A := 50310.06;
    B := 3521.7;
    //C := 53831.76;
    C := A + B;
    
    ERV := 1.235025;
    
    D := ROUND((A * ERV),0.01,'<');
    E := ROUND((B * ERV),0.01,'<');
    F := ROUND((C * ERV),0.01,'<'); 
    
    MESSAGE('D = %1\E = %2\F = %3',D,E,F)
    
    with all variables of data type Decimal
    Luc van Vugt, fluxxus.nl
    Never stop learning
    Van Vugt's dynamiXs
    Dutch Dynamics Community
  • Aravindh_NavisionAravindh_Navision Member Posts: 258
    Thanks lvanvugt for your reply. Below are my answers...

    1. ERV := 1.235025;

    2. F = D + E
  • Aravindh_NavisionAravindh_Navision Member Posts: 258
    I am getting few differences in output when compared to the actual calculation. Difference of .03 is showing in this case.
  • lvanvugtlvanvugt Member Posts: 774
    What does your code look like?
    Luc van Vugt, fluxxus.nl
    Never stop learning
    Van Vugt's dynamiXs
    Dutch Dynamics Community
  • vaprogvaprog Member Posts: 1,141
    You must not expect F = F' with
    F = D + E and
    F' = ROUND(C * ERV)

    Are you sure, the values you gave us are the actual values or might this be the true values rounded for display?
  • Aravindh_NavisionAravindh_Navision Member Posts: 258
    Thanks vaprog,

    The examples that I have given here are the real ones. This I am doing for Invoice. If even .02 difference occurs, it will be questioned in auditing.
  • ChinmoyChinmoy Member Posts: 359
    Are all these A,B,C,D,E,F,ERV variables or fields from a table? This may happen if the "DecimalPlaces" property of the decimal fields is set with some value, say 2:2, or for that matter anything else.

    Check this option also if the calculation in question is getting the values from table fields.. :)
Sign In or Register to comment.