How to allow decimal values in integer field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2020 01:43 AM
In a Integer type field it should allow decimal values as well.I have followed below script but it is not accepting decimal values
Client Script : onChange
function onChange(control, oldValue, newValue, isLoading, isTemplate)
{
if (isLoading || newValue === '')
{
return;
}
var reg = /^[0-9]*\.[0-9]{2}$/;
var ans = g_form.getValue('field_name');
if(!reg.test(ans))
{
g_form.clearValue('field_name');
}
}
- Labels:
-
Incident Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2020 01:58 AM
Hi Siri,
Since its integer field it will not accept decimal values. Even if you manage it will round-off decimal.
You can use string field if required & then use the .toFixed(2) to get two decimal values.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2020 02:01 AM
Hello,
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;
}
If answer is helpful mark correct!
Thanks,
Pratiksha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2020 02:41 AM
Its not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2020 03:05 AM
Hello Siri,
Please refer below script and do changes accordingly in your onChange client script.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var regexp = /^[0-9].*$/;
if(!regexp.test(newValue)) {
alert('Only numbers and dot value allowed');
g_form.clearValue('u_field_name');
g_form.setValue('u_field_name','');
}
I hope this will help you.
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response useful to you and help others to find information faster.
Thanks,
Tejas