web
You’re offline. This is a read only version of the page.
close
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.

I have the same question (0)
  • GirishS Profile Picture
    27,827 Moderator on at

    Hi koti,

    You can make use of "decround" function.

    Thanks,

    Girish S

  • Koti9999 Profile Picture
    55 on at

    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.

  • Martin Dráb Profile Picture
    237,768 Most Valuable Professional on at

    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.

  • Suggested answer
    Komi Siabi Profile Picture
    13,093 Most Valuable Professional on at

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

  • Koti9999 Profile Picture
    55 on at

    Thanks a lot Komi..

    I applied the same logic, achieved  the desired result.

    Thanks,

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

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 704 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 570 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 408 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans