Is there any attribute to round off the decimal value

amaradiswamy
Kilo Sage

Hi All,

I have created a field(String data type) and populating average value to that field. The process is fine but its is populating upto 8 decimal points because the field is string type. is there any available attribute(for the variables) to round off the average value and populate the value with only two decimal points(a.bc).

Thanks & Regards,

Swamy

1 ACCEPTED SOLUTION

Naveen Kumar J
Tera Expert

Please try x = x.toFixed(2);


View solution in original post

5 REPLIES 5

mansooromar
ServiceNow Employee
ServiceNow Employee

You can do an onBefore business rule (insert/update) which gets the value of your decimal field and fixes it to two decimal places:



function onBefore(current, previous) {


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



  current.YOUR_DECIMAL_FIELD = getDec;


}



Kind regards,


Mansoor Omar | Technical Support Engineer   User Experience