Question

I've got the following onChange code. It updates my div1 with the value. The value is a numeric value and I would like to round it so that there is no decimal point. Can anyone tell me how this can be done?

So for example value 12.987654321 will be 13

onChange="document.getElementById('div1').innerHTML=this.value"
Was it helpful?

Solution

There is a Math.round function you could use like this (otherwise your code looks fine to me):

onChange="document.getElementById('div1').innerHTML=Math.round(+this.value)"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top