Value After Decimals Places Changes in Field(Decimal)

fortius_cvafortius_cva Member Posts: 70
Hi
Greetings

I have a Quantity(Decimal) Field in a table. It is showing a value of 128.39284 in the form. But when in zoom the record and look at the values it is showing me value as 128.39284123456.

why is it happening?? because of this reason, i am not able to compare this field with another field which has the same value(12.39284)..
Thank You
********
Friend Ship is just like breeze.. you can't smell it, touch it,hold it.
********

Comments

  • nhsejthnhsejth Member, Microsoft Employee Posts: 34
    When you want to compare two decimals, you shoudl always round the numbers to a known precision for you compare the values. Ignorring this step will in most cases result in failing comparison due to tiny roundings that happend during the calculations. The numbers migth look the same, but can have a difference on the last digit.

    The numbers you see in the form has been rounded for display purposes, but the data behind has not, which is why your comparison fails. Use the AL function ROUND

    Sample code (d1 through d4 are decimals)
    d1 := 123.123456789;
    d2 := 123.1234567;
    
    d3 := ROUND(d1,10000);
    d4 := ROUND(d2, 10000);
    
    if d3 <> d4 then
      error('Wrong rounding %1 <> %d', d3, d4);
    
    _________________
    Niels-Henrik Sejthen
    Senior Software Developer
    Microsoft Dynamics NAV

    The information in this post is provided "AS IS" with no warranties, and confers no rights. This post does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion.
Sign In or Register to comment.