web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Values being rounded automatically when we don't want it.

(0) ShareShare
ReportReport
Posted on by

Hello, everyone!

I'm using Dynamics AX 2009 and I have the following code in X++:

Real r;

;

r = 0.259315 + 0.259315;

info(strFmt("%1", r));

Although the result of this operation is 0.51863, the value being shown is 0.52. Is there anyway for AX not to round the number?

We're having a problem with a report, which sums the prizes of some items. The sum of the prices of the items is different than the price shown in the report.

Thanks in advance!

Luiz Bezerra

*This post is locked for comments

I have the same question (0)
  • Bilal Issa Profile Picture
    4,370 on at

    Hi Luiz ,

    this related to the extended data type you are using , by default it has 2 decimal points, but you change that property to 4 if you need.

    Regards,

    Bilal

  • Community Member Profile Picture
    on at

    Hello!

    Thank you for the quick answer. Well, we already tried to create a new extended data type with 8 decimal points, but the results are the same... are there any other suggestions?

  • Bilal Issa Profile Picture
    4,370 on at

    Hi ,

    Please try to change the number of decimal points for the control in the report  as well.

    Regards,

    Bilal

  • Suggested answer
    Joris dG Profile Picture
    17,775 on at

    Also, your number is not *actually* rounded, AX only rounds if you're asking it to. It's just shown on forms and reports as if it were rounded (similar to how you can tell Excel to show a number of decimals in a cell, although the value of the cell may go far beyond what is shown). In your example of r = 0.259315 + 0.259315; the "r" value actually is correct. Try changing your info statement to something like this:

    info(num2str(r, 0, 10, 1, 0));

    In this case I'm telling the system to convert the real to a string with 10 decimal places. This shows the "r" variable actually contains all decimals.

    To other people's points, the displaying on forms and reports of a certain number of decimals is controlled by the extended data type, or by properties of the control on the form or report. If you create a new extended data type with 8 points and it's not working, you must have a mistake in your work somewhere. Make sure the data type is actually used by the field etc. If you're using the "real" data type instead of the EDT anywhere (like the return type of a display method) you'll be back to the standard 2 decimals.

  • Mourad Profile Picture
    70 on at

    Hello,

    I'm Having the same issue, but i cannot succeed to have my decimal correct even after using an ETD with 12 decimals.

    here is the little code :

    temp ="123.4567";
    info(temp);
    val = System.Convert::ToDecimal(temp);
    info(strFmt('%1',val));
    info(strFmt('%1',str2num(temp)));

    and the result is :

    123.4567
    123.46
    123.46

    Thank you veruy much.

  • Martin Dráb Profile Picture
    238,127 Most Valuable Professional on at

    You're use the default conversion in both cases and it always uses two decimal places. If you want different behaviour, you need a different conversion.

    Please look just one reply above to see how to covert numbers to string with more decimals.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#2
TAHER Mehdi Profile Picture

TAHER Mehdi 3

#3
Nakul Profile Picture

Nakul 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans