Notifications
Announcements
No record found.
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
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.
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
You can refer this:
www.powerobjects.com/.../rounding_numbers-in-microsoft-dynamics-crm
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
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); }
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
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
I didn't get it.. You are trying to setValue for Calculated field?
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.
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.
SA-08121319-0 4
Calum MacFarlane 4
Alex Fun Wei Jie 2