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

Chavan AP
Tera Guru

Please refer below:

 

 

 

var x= parseFloat(current.u_field);

 

x= x.toFixed(2);

 

 

https://community.servicenow.com/community?id=community_question&sys_id=62e98729db5cdbc01dcaf3231f96...

Glad I could help! If this solved your issue, please mark it as ✅ Helpful and ✅ Accept as Solution so others can benefit too.*****Chavan A.P. | Technical Architect | Certified Professional*****

Andrew_TND
Mega Sage
Mega Sage

Hello,

Do you have an example of the script your using?

For example in this calculated field you normally just add toFixed(2) the line and it rounds it.

(function calculatedFieldValue(current) {
	var total = (current.u_test1 + current.u_test_2).toFixed(2);
	return total;
})(current);

Please mark as helpful or if its resolved it mark as correct!

Hello Andrew, 

it helped me when the results return more than two decimals, but when this number it's zero doesn't work. it's ignoring the number zero.

For example:

Case 1 - Ex: If it's 10,987 it's transformed in 10,99 [Behavior it's OK]

Case 2 - Ex: If it's 10,90 it's transformed in 10,9 instead of  10,90

 

Case 3 Ex: If it's 10,00 it's transformed in 10 instead of 10,00

 

But in all cases I need that behavior to be the same as in case 1

How can I fix it ?

 

Thank you, 

Jessy