Why can't I set decimals in a decimal field?

e_wilber
Tera Guru

I have a custom decimal field that I'm trying to update via a business rule:

        met.u_total_value = 4.25;
        met.update();
 
It's updating the field to 4 instead of keeping the decimals. Why is my decimal disappearing and how do I keep it?
7 REPLIES 7

Vishal Jaswal
Giga Sage

Shivalika
Mega Sage

Hello @e_wilber 

 

It's because it takes integer by default. 

 

You need to parse it to float or double specifically. 

 

Use below 👇 

 

var decimalValue = parseFloat(met.u_total_value);

 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

Ankur Bawiskar
Tera Patron
Tera Patron

@e_wilber 

are you sure the field type is Decimal and not Integer?

what happens when you manually enter?

share the field configuration screenshots here

try this once

        met.u_total_value = parseFloat(4.25).toFixed(2);
        met.update();

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,
 
This is what I'm trying right now and it keeps setting it to 4.
        var tst = 4.25;
        met.u_total_value = parseFloat(tst.toFixed(2));
        met.update();
 
It shows this is a decimal field:
e_wilber_0-1744032991890.png