Skip to main content

Notifications

Announcements

No record found.

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
    Koti9999 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
    Komi Siabi 12,692 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
    Martin Dráb 230,235 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
    Koti9999 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
    GirishS 27,832 Super User 2024 Season 1 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans