Client script for decimal points

User_267
Tera Contributor

Hi everyone iam using this script, to check if somebody enters number or not, if it is not a number then it should show alert and if it is number then it needs to be in this format $12.00. but the code is not working even when a number is entered it is showing error.

6 REPLIES 6

chetanb
Tera Guru

Hello @User_267 

 

Why can't you set formatted value back in the function itself like-.

 

function onChange(control, oldValue, newValue, isLoading) {
// Check if the form is still loading
if (isLoading || newValue === '') {
return;
}

// Format the input as a decimal with a dollar sign
var formattedValue = formatAsCurrency(newValue);

// Set the formatted value back to the field
g_form.setValue(control.name, formattedValue);
}

function formatAsCurrency(value) {
// Format the input as a decimal with a dollar sign
var decimalValue = parseFloat(value).toFixed(2);
var formattedValue = '$' + decimalValue;

return formattedValue;
}

 

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

Regards,

CB

 

Chaitanya naram
Kilo Sage

Hi @User_267 

If you are using currency type variable, you need to set the value in the below format
var currency="USD"; //give the currency code whichever you want to append
var finalValue='12.00';
g_form.setValue('variableName',currency+';'finalValue);

 

 

Thanks & Regards | Chiranjeevi Chaitanya Naram
Kindly mark the answer Correct and Helpful if it helps to resolve your issue.

But when iam entering number also it is showing error. But when we enter number it shouldn't show error.how to do this ?

Hello @User_267 I did not get what you are saying.

 

Can you please provide screenshot or explain clearly.

Thanks & Regards | Chiranjeevi Chaitanya Naram
Kindly mark the answer Correct and Helpful if it helps to resolve your issue.