Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Number round off

(0) ShareShare
ReportReport
Posted on by 55

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.

  • Koti9999 Profile Picture
    55 on at
    RE: Number round off

    Thanks a lot Komi..

    I applied the same logic, achieved  the desired result.

    Thanks,

  • Verified answer
    Komi Siabi Profile Picture
    12,772 Most Valuable Professional on at
    RE: Number round off

    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));

  • Martin Dráb Profile Picture
    231,837 Most Valuable Professional on at
    RE: Number round off

    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.

  • Koti9999 Profile Picture
    55 on at
    RE: Number round off

    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.

    Thank  you in advance.

  • GirishS Profile Picture
    27,823 Moderator on at
    RE: Number round off

    Hi koti,

    You can make use of "decround" function.

    Thanks,

    Girish S

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

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,025 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,837 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans