문제

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"
도움이 되었습니까?

해결책

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)"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top