Notifications
Announcements
No record found.
Hi Experts,
I've a requirement to round off a number to nearest number.
weight is the field to round off.
like if the weight is 0.5 and below it should consider 0..if it is 0.75 and above the weight should round off to nearest number .i.e 1.
Pleese suggest on this.
Thank you in advance.
Hi koti,
You can make use of "decround" function.
Thanks,
Girish S
Thank you Girish for your quick reply and suggestion !!
i wrote the code like below.
decRound(salesLine.ItemNetWeight, 0).
it is working (if the netweight is below 0.5 means 0.4..it is rounding off to 0).
one scenario it is failing.if itemNetWeight is 0.5 it is considering 1 .
the requirement is if the netweight is above 0.5 like 0.6 and above ..it is round off to 1.
the scenario will be like this.
0.1 = 0
0.2 = 0
0.3=0
0.4=0
0.5=0
0.6=1
0.7=1
0.8=1
0.9=1
1=1
please suggest on this.
Which version of AX is it about?
Think carefully whether you really want a different way of round than used by the rest of AX. If you're sure, then you can either look for a pure X++ solution or utilize .NET. I'm not aware of any X++ function doing what you want, but you surely could implement this way of rounding by yourself. An easier (and safer, because it's tested) solution may be using System.Math::Round(). The third argument allow you to choose the rounding strategy.
Hi,
You can try this.
real _amount; // You can pass this a an argurment in your method real decimals; int intNum; _amount = 12.7; intNum = _amount; decimals = _amount - intNum; if (decimals <= 0.5) { _amount = intNum; } else { _amount = decRound(_amount,0); } Info(strFmt("%1",_amount));
Thanks a lot Komi..
I applied the same logic, achieved the desired result.
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Martin Dráb 704 Most Valuable Professional
André Arnaud de Cal... 570 Super User 2025 Season 2
BillurSamdancioglu 408 Most Valuable Professional