Javascript to force decimals in 0.25 steps

I have a few input values on a form that must be in 0.25 steps, how do I force this ? alternatively how do I automatically enter the correct vales as the user types and disallow any other values ie: as the firstnumber is typed (say 3) then .00 is added, then as the decimal point and the first decimal value is entered which must be either 0, 2, 5 or 7 then the appropriate second decimal is added which would be 0 or 5 as appropriate. I guess I will need an alert for any other values that might be entered in error?

I have googled and there are plenty of solutions to round to the nearest decimal but not to actually force 0.25 steps
I am sorry, I have absolutely no idea where to start:confused:

You mean like this ,

<script type="text/javascript">
   var fixed = 0.25
   function TextChange(e)
   { 
        if (isNaN(e.value)){ alert('must be numeric'); return  }
       
	var v = Math.floor( (parseFloat( e.value.toString().split(".")[1].substring(0,2) ) * 0.01)/fixed ); 
     e.value  =  (e.value | 0 ) +  fixed * (isNaN(v) ? 0 : v);   
   }
</script>

<input type="number" onchange="TextChange(this)" />

Yes nearly, I need there to be exactly 2 decimal places ie 1.00, 1.25, 1.50, 1.75, etc

Or the other alternative leave the value as typed by the user and give an pop up error if any other decimal is used?

Thanks for your help.

OK. javascript uses floating point arithmetic operations (as compiled from C code).

Floating point does not always represent some numbers precisely, especially after several operations, e.g., addition, multiplication, etc. see -

What Every Computer Scientist Should Know About Floating-Point Arithmetic

You can convert fp -> string then display. You can also use convert.log() with a %f format specifier if your version supports a %f format specifier.
see:
JavaScript equivalent to printf/string.format - Stack Overflow

0.5 and 0.25 are simple binary fractions of 1, floating point will represent it perfectly as long as it has 2+ bits of fraction. For 32-bit floats, anything inside +/-2 million will work perfectly.

Computationally speaking, this is the most direct method: Multiply by 4, strip off decimals, divide by 4.

Math.floor(var*4) / 4

And then as the final step, force it to two decimals as follows:

num.toFixed(2)