Catalog variable to accept decimal values up to 2 digits

Nagashree5
Tera Contributor

Hi All,

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 which should rounded to 100.12

 Note : It should accept both numbers and decimal values 

 

I have written the below script. 

function onSubmit() {
var cs = g_form.getValue('cost');
var letter = /^[0-9.]+$/;
if ((cs.match(letter))) {
var value = Math.round(cs*100)/100; 
//alert(value);
g_form.setValue('cost',value); 
} else {
// g_form.addErrorMessage('Add only numerics');
g_form.showErrorBox('cost','Add only numerics');
g_form.submitted = false;
return false;

}

}

 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.

1 ACCEPTED SOLUTION

manjusha_
Kilo Sage

@Nagashree5 

Try as below-

var cs = g_form.getValue('cost');
var letter = /^[0-9.]+$/;
if ((letter.test(cs))) {

 

}

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact

 

Thanks,

Manjusha Bangale

View solution in original post

1 REPLY 1

manjusha_
Kilo Sage

@Nagashree5 

Try as below-

var cs = g_form.getValue('cost');
var letter = /^[0-9.]+$/;
if ((letter.test(cs))) {

 

}

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact

 

Thanks,

Manjusha Bangale