Just guessing.... Maybe you are getting problems dealing with non-whole numbers? 0 and 1 is a hard one if you are using integers
If you are having problems with getting the fraction, you dont need to clamp anything. Just cast the variable into a float like this:
That will allow the decimal value that comes after the whole number.