Formatting Currency Field with Decimal Places - OnChange Client Script

Jordan Rose1
Kilo Expert

I have what I feel should be an easy fix (at least in JavaScript outside of ServiceNow).  I have a requirement of displaying a currency field with two decimal places no matter what the value is.  When I edit the field client-side in a form and input a value that is just an integer, I need the value to display '.00' after the integer.  

I am able to do this though onChange by changing ANOTHER field's value using .toFixed(2), but I don't know how to change the newValue (current value) through an onChange client script.  I'm sure this is disabled because of potential looping issues.

How can I get a fixed two decimal format to be added to all user inputted values on the client side for a currency form field?

Thanks

1 ACCEPTED SOLUTION

Jordan Rose1
Kilo Expert

Hi Ankur,

 

Your answer was just a question, so I'm not sure how it could be correct.  I found out a workaround that i'll share with the community.  I ended up using jQuery on the Form Widget to add an onBlur function to all data-type="currency" fields in the form.  I end up doing my currency formatting in that onBlur script and that seems to work properly.

View solution in original post

5 REPLIES 5

Harshada3
Tera Expert

Hello @Ankur Bawiskar ,

 

I am setting a calculated float value in currency field. The value is calculated in script include which is called by onchange client script. When the total value exceeds 7 digits the value is shown with decimal point.

link to my question :  https://www.servicenow.com/community/itsm-forum/currency-value-not-displaying-8-digit-total-sum/td-p...

 

would you please look into it and share your opinions? 

 

Regards,

Harshada