- 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-07-2022 02:56 AM
I am using below code but allowing me the numbers but i need to allow the decimals as well update 4 digits
var regexp = /^[+]?\d*$/;
if (!regexp.test(newValue)) {
alert('Please enter numeric value');
g_form.setValue('v_sec_review_unknown', '');
g_form.clearValue('u_confirmed_cost_of_training_excluding_taxes');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2022 10:26 AM
Hi All,
i am able to add the decimal values but i need to make them round of 3 digits . Can any one help me on this .
ex: 100.12345 then it should be come as 100.123 or 100.124
var regexp = /^[0-9.]*$/;
if (!regexp.test(newValue)) {
alert('Please enter numeric value');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2022 10:34 AM
Hi All,
Can any one help me on this ,
Thanks in Advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2022 06:22 AM - edited 12-09-2022 06:39 AM
Hi @sushma9 ,
I have created an Onsubmit catalog client client script. Please try this.
function onSubmit() {
var cs = g_form.getValue('cost');
var letter = /^[0-9.]+$/;
if ((cs.match(letter))) {
var value = Math.round(cs*1000)/1000; // 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;
}
}
Thankyou,
prithvi