Dynamics AX
  RSS Feed  LinkedIn  Twitter
Want to turn you're data into a true asset? Ready to break free from the report factory?
Ready to gain true insights that are action focused for truly data informed decisions?
Want to do all of this across mutliple companies, instances of Dynamics and your other investments?
Hillstar Business Intelligence is the answer then! (www.HillstarBI.com)

Hillstar Business Intelligence for Microsoft Dynamics AX and NAV on Mobile, Desktop, Tablet


Let us prove to you how we can take the complexity out of the schema and truly enable users to answer the needed questions to run your business! Visit Hillstar Business Solutions at: www.HillstarBI.com

Wednesday, December 07, 2005

Rounding in X++

I recently had to do some rounding in X++ on a real variable. This was due to some custom Rebate code. Anyway, I have some sample code here for rounding. I found it strange really how the synatx had to be and could not find anywhere on the internet what the synatx needed to be, so here you go:

server static void RoundExample(Args _args)
{
real r = 7.8413;
real a;
;

a = round(r,0.01);
r = a;
}

Anyway, if you put 0.00 in the decimal, then no decimal is used, but if you supply 0.01 in the decial variable then it works great. So if you wanted to round to 0.0000 then you would need to put there 0.0001.

Find a job at: www.DynamicsAXJobs.com

2 Comments:

Blogger Steeve said...

The syntax looks strange because the function can do more then straight decimal rounding. I don't know how to explain that in words but just take a look at the following code and you'll see what "special" rounding I'm talking about.

real a = 4.266;
;

info(num2str(round(a, 0.01), 0, 4, 2, 3)); // show 4.27
info(num2str(round(a, 0.02), 0, 4, 2, 3)); // show 4.26
info(num2str(round(4.272, 0.02), 0, 4, 2, 3)); // show 4.28

8:37 AM  
Blogger brandon said...

I believe the rounding may be another peice of X++ that is either strange and flaky in the way it works. Another issue I have ran into is just general precision problems with real's. These two issues may be combined?? Maybe someone else who has had more experince with this rounding code can give a good example here and I will post it!

Thanks for the comments!

10:09 AM  

Post a Comment

Links to this post:

Create a Link

<< Home


Copyright 2005-2011, J. Brandon George - All rights Reserved