Why my typing cursors moves to the beginning when typing period in HTML number input?

<input type="number" oninput="this.value=this.value.slice(0,5)"/>

I’m trying to limit the number of char allowed in the field, but when typing period, the cursor moves to the beginning and the period symbol is not typed?

How can I fix this behavior?

Thanks

Specified oninput field to slice the value of input field, it worked fine but when typing period symbol the cursors moves to the front, it doesn’t do that the second time.