Quote:
Originally Posted by DarkStar
the slider displays integer values between 0 and 100, not the remainders.
|
You're right. I don't know exactly why it doesn't work as you'd expect but I can have a guess. I'm sure one of the Cockos team will correct me if I'm wrong.
JS is, as far as I know, C++ in disguise. I was told in another thread that all JS variables are of the floating point type and if I recall correctly, the % operator in C++ only works for integers. It's been a while since I tried so I might be wrong but at the very least, it doesn't do what you'd expect it to.
So what I think happens is that both operands get converted to integers behind the scenes and everything after the decimal point gets discarded and there's no rounding. So if you do 1.7 % 100, what you get back is the result of 1 % 100.
3 % 2 gives a result of 1.
3.5 % 2 still gives a result of 1, even though you'd expect 1.5.
You could try something like this...
Code:
val1 = 3.5;
val2 = 2;
val1 *= 1000; //3500.0
val2 *= 1000; //2000.0
result = (val1 % val2) / 1000; //1.5