- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
9 hours ago
Hi all ,
var amountA = parseFloat(g_form.getValue('u_amount_a')) ;
var amountB = parseFloat(g_form.getValue('u_amount_b')) ;
var result = amountA - amountB;
g_form.setValue('u_result', result);
Answer is coming in the output NAN .
Could you please help me on this
Thanks and Regards,
Chandan
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
8 hours ago
Hello @chandan86patra ,
Try this :
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
var a = parseFloat(g_form.getDecimalValue('u_a')) || 0;
var b = parseFloat(g_form.getDecimalValue('u_b')) || 0;
var total = a + b;
g_form.setValue('u_c', total.toFixed(2));
}
If this helps you then mark it as helpful and accept as solution .
Regards,
Aditya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
9 hours ago
Hello @chandan86patra ,
can you try the following snippet:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
var amountA = parseFloat(g_form.getValue('u_amount_a')) || 0;
var amountB = parseFloat(g_form.getValue('u_amount_b')) || 0;
g_form.setValue('u_result', amountA - amountB);
}
Please mark this answer as helpful/correct, if it serves your purpose.
Best regards,
Puru.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
9 hours ago
Hi @chandan86patra ,
The issue is that currency fields return their values in a format such as INR;1000.00, rather than a plain
numeric value. Since parseFloat() cannot parse the entire string in this format, it returns NaN.
You need to extract the numeric portion of the currency value before performing the calculation. You can achieve this by splitting the value using ; and parsing the second part.
You can try the following Client Script:
var amountA = g_form.getValue('u_amount_a');
var amountB = g_form.getValue('u_amount_b');
if (!amountA || !amountB) {
g_form.setValue('u_result', '');
return;
}
var valueA = parseFloat(amountA.split(';')[1]);
var valueB = parseFloat(amountB.split(';')[1]);
var result = valueA - valueB;
g_form.setValue('u_result', 'INR;' + result);For example, if u_amount_a returns INR;1000.00 and u_amount_b returns INR;400.00, the script extracts the numeric values, subtracts them, and sets the result to INR;600.
Please ensure that the currency code used when setting the result matches the currency you intend to use.
I hope this helps! If this resolves your issue, please mark the response as helpful and accept the solution.
Regards,
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
8 hours ago
@HarishKumar6668 @pururavasin it is giving NAN output
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
8 hours ago
Hello @chandan86patra ,
Try this :
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
var a = parseFloat(g_form.getDecimalValue('u_a')) || 0;
var b = parseFloat(g_form.getDecimalValue('u_b')) || 0;
var total = a + b;
g_form.setValue('u_c', total.toFixed(2));
}
If this helps you then mark it as helpful and accept as solution .
Regards,
Aditya