Reputation: 682
In Java we use the double or float data type to get results in decimal points. However how do i do this in Javascript? The current calculation i am doing is:
a1 += (a1 * results[0][index]) / 100;
EDIT, My Apologises, There was a mistake on my side from using the wrong variables.
Upvotes: 1
Views: 761
Reputation: 413737
All numbers in JavaScript are like Java "double" values. The general problem one encounters in JavaScript is how to do math as if they're not floating-point.
Thus in an expression like yours, if the numerator is not evenly divisible by 100 you'll get a value with a fractional part. You can use "Math.round()" or "Math.floor()" to round or truncate the fraction, but you'll definitely get it.
Upvotes: 3