- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 02:38 AM
Hi ,
I have variable called Cost and it should accept the both decimal values and number. How can i achieve this.
Example :
1.Cost : 100
2. cost : 1000.12345
Note : It should accept both numbers and decimal values
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2022 08:55 AM
Hi @sushma9
function onSubmit() {
var cs = g_form.getValue('cost');
var letter = /^[0-9.]+$/;
if ((cs.match(letter))) {
var value = Math.round(cs*100)/100; // 10 defines 1 decimals, 100 for 2, 1000 for 3
//alert(value);
g_form.setValue('cost',value); //Please set value according to your need
} else {
// g_form.addErrorMessage('Add only numerics');
g_form.showErrorBox('cost','Add only numerics');
g_form.submitted = false;
return false;
}
}
Please modify the code for two decimal positions. Please find the attached screenshot.
Instead of var value = Math.round(cs*1000)/1000; , i gave var value = Math.round(cs*100)/100; .
Thankyou,
Prithvi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2022 08:59 AM - edited 12-10-2022 09:02 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2022 02:27 AM
Hi Prithvi ,
Thanks for your reply .
Its working fine almost 95% but what i need is when you enter 124.567 then it should come as 124.57 after the 6 the values is 7 so it should add 1 to 6 and has to come as 124.57.
note :
if any value after 5 then it should add 1 to previsoue number
ex : 400.009 , 346.127
out put : 400. 01 , 346.13
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2022 08:55 AM
Hi @sushma9
function onSubmit() {
var cs = g_form.getValue('cost');
var letter = /^[0-9.]+$/;
if ((cs.match(letter))) {
var value = Math.round(cs*100)/100; // 10 defines 1 decimals, 100 for 2, 1000 for 3
//alert(value);
g_form.setValue('cost',value); //Please set value according to your need
} else {
// g_form.addErrorMessage('Add only numerics');
g_form.showErrorBox('cost','Add only numerics');
g_form.submitted = false;
return false;
}
}
Please modify the code for two decimal positions. Please find the attached screenshot.
Instead of var value = Math.round(cs*1000)/1000; , i gave var value = Math.round(cs*100)/100; .
Thankyou,
Prithvi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2022 08:59 AM - edited 12-10-2022 09:02 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2022 09:41 PM
Hi ,
Thanks for your support .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2023 05:46 AM
Hi @Prithvi_b ,
Thanks for the script. It is working fine but there is a java script browser console error is coming which says "cs.match is not a function". How do I avoid this error. Please help!
Thank you in Advance.