Below is the JavaScript code for three fields 1- SubTotal 2- Actual VAT 3- VAT (this is the VAT result as per our requirement), everything is working fine whenever I'm giving any amount in the subtotal field it gives me the correct result without rounding off with 2 decimals. except for two number 41 & 51, with these two numbers, I suppose to get "2.05" and "2.55" respectively but the result what I'm getting with the below code are "2.04" & "2.54", unable to understand why. Is something wrong with my code? Could you please help me in solving this?
temp1 = VATnew.rawValue * 100;
//app.alert("temp1: " + temp1);
//convert to int. to drop remaining decimals
temp2 = parseInt(temp1);
//app.alert("temp2: " + temp2);
// divide by 100 to shift back 2 places
temp3 = temp2 / 100;
//app.alert("temp3: " + temp3);
// return data to field
this.rawValue = temp3;
Views
Replies
Total Likes
The parseInt() method has a second parameter called radix. Its used the define the number base, for decimals its 10.
You should use it to avoid that the input is converted into a wrong number by assuming the wrong base.
parseInt(temp1, 10);
Views
Replies
Total Likes
Views
Replies
Total Likes
This seems to work - check it out
I guess 5% VAT?
function truncate(number)
{
if (number > 999) {
return number > 0
? Math.floor(number)
: Math.ceil(number);
} else {
return number;
}
}
Views
Replies
Total Likes
Thanks for the reply Kosta, but I'm unable to get any result in the third field.
I'm frustrated now, since two days I'm struggling with this. Please Please Help me.
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
This forum system is really weird.... again
I just realized that the screenshot does not show the whole thing - you need an additional line
truncate(NumericField2.rawValue*100)/100 at the end
Views
Replies
Total Likes
Thanks for your reply and help Kosta.
Great, now it is working fine but not for all number...
I tried will all the same number as you did and one number extra like 1502.
it is not working fine for this number. Kindly check this below image...
Views
Replies
Total Likes
Views
Replies
Total Likes
Thanks for your reply and help Kosta. Great, now it is working fine but not for all number... I tried will all the same number as you did and one number extra like 1502 and more. it is not working fine for these numbers. Kindly check this below image...
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Yes, now it's working fine. but sorry the other things got disturbed with this...
I actually want this VAT value without roundoff and only with 2 decimals, earlier code was giving the value without roundoff but few random numbers were having issues.
now with this new line, all numbers are working fine but the VAT result is round off.
Views
Replies
Total Likes
Views
Replies
Total Likes
Yes please, I'm already glad and thankful for you kind help.
Kindly help me to achieve this, I hope you know what I actually want.
let me explain it again.
I just want the 5% of VAT result in only 2 decimals and without round off
accurately for all numbers.
Views
Replies
Total Likes
Here we try a completely different approach
The third field is a Text Field as the result is a manipulated string
Set the pattern of the second field as shown here
The calculate script
function toFixed(num, fixed) {
var re = new RegExp('^-?\\d+(?:\.\\d{0,' + (fixed || -1) + '})?');
return num.toString().match(re)[0];
}
toFixed(NumericField2.formattedValue,2)
No unpredictable rounding with this one...
Check if you find any values where this does not work...
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies