سؤال

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