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
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
1 Comments:
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!
Post a Comment
<< Home