How round the value after two decimal point

SNOW39
Tera Expert

We have a filed in our catalog item name Price. If the enter value 10.98723 it should round to 10.99. How to do this?

7 REPLIES 7

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Multiple options for this.
One could be to add:

.toFixed(2)

Tested below in Background script:

var price = 10.98723;

gs.info(price.toFixed(2));

Result:

10.99

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn

Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

AbhishekGardade
Giga Sage

Hello SNOW,

You might want to ensure it is a floating point number first.

var myHours = parseFloat(current.u_hours_worked);

myHours = myHours.toFixed(2);

Please mark as Correct Answer and Helpful, if applicable.
Thank You!
Abhishek Gardade

Thank you,
Abhishek Gardade

Tried this already.Not working

Pooja Yadav3
Mega Expert

Hii,

 

     var getDec = current.YOUR_DECIMAL_FIELD.toFixed(2);

     current.YOUR_DECIMAL_FIELD = getDec;

 

Go through the below link which will help you for controlling the decimal field values

 https://www.servicenowguru.com/system-definition/controlling-decimal-field-places/

 

I hope this will helps you.

Please mark as Correct Answer and Helpful, if it helps you.

 

Thanks,

Pooja Yadav