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 :
Microsoft Dynamics CRM (Archived)

JavaScript to round decimal field down

(0) ShareShare
ReportReport
Posted on by 341

Hi,

would anyone know the code for rounding a decimal field down in Dynamics using javascript?

iv seen a few posts elsewhere suggesting math.floor might be applicable

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    shivaram Profile Picture
    3,315 on at

    Hi,

    yes, you can use math.floor for downward to its nearest integer.

    And math.round will check the value and based on value it will decide to round whether upward or downward

    Ex:

    var a=1.4

    math.round(a)==1

    var b=1.5

    math.round(b)==2

    Hope it helps you.

  • smcconnell Profile Picture
    341 on at

    Hi Shivaram,

    many thanks for the quick response.  

    apologies my skills here arent very good, could you advise on the actual syntax for performing this on a Dynamics 365 field?

    regards

    Scott

  • Suggested answer
    Rajkumar Rajaraman Profile Picture
    on at

    You can refer this:

    www.powerobjects.com/.../rounding_numbers-in-microsoft-dynamics-crm

  • Suggested answer
    shivaram Profile Picture
    3,315 on at

    Hi,

    Lets say you have a decimal field which is having schema name as "new_decimalnumber", then you can use like following

    var decimal=Xrm.Page.getAttribute("new_decimalnumber").getValue();

    var downwardDecimal=math.floor(decimal);

    Thats it.

    Hope it helps you

  • smcconnell Profile Picture
    341 on at

    Hi Shivaram,

    thanks again.  still having issues though, my code below doesn't appear to manipulate the number downwards, it doesnt give an error, just doesnt do anything.  i have it running on Form Load and Save.  

    function RoundDown()
    {
    var num = Xrm.Page.getAttribute("fieldname").getValue();
    var rounded = Math.floor(num);
    Xrm.Page.getAttribute("fieldname").setValue(rounded);
    }

  • shivaram Profile Picture
    3,315 on at

    Hi,

    I trust that, field where you want to set data is either single line or Whole Number. If yes, then your code is simply perfect. Just try to debug. And one more thing, you cant't update for rollup/Calculated fields

  • smcconnell Profile Picture
    341 on at

    Hi Shivaram,

    Ok that explains the issue then the field is calculated.

    I can get round that issue though by passing the number to another field and working off that.

    thanks

    Scott

  • shivaram Profile Picture
    3,315 on at

    I didn't get it.. You are trying to setValue for Calculated field?

  • smcconnell Profile Picture
    341 on at

    Hi Shivaram,  yes that was my mistake, i was trying to set the value on a calculated field.

    im guessing one option would be to either use a workflow or javascript to pass the value from the calculated field to a new whole number field and perform the Math.floor function on that?

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans