Hur skriver man för att avrunda ett tal till endast 1 decimal.
T.ex.: 2.42245 till 2.4 bara.
------------------
/JE
4 svar · 839 visningar · startad av JE
Hur skriver man för att avrunda ett tal till endast 1 decimal.
T.ex.: 2.42245 till 2.4 bara.
------------------
/JE
Typ så här: Math.round(2.42245*10)/10
Och för två decimaler: Math.round(2.42245*100)/100
osv...
/ J
Johnsen skrev:
Typ så här: Math.round(2.42245*10)/10
Och för två decimaler: Math.round(2.42245*100)/100
osv...
/ J
Enligt ovanstående resonemang borde
<input name="knp" type="button" id="knp" onClick="Math.round(document.vvp.points.value=(document.vvp.volym.value/100)*(document.vvp.kcal.value/60 + document.vvp.fett.value/9)*10)/10" value="ge points" />
fungera...
Men det gör inte det, rundar inget av..
Testa
<input name="knp" type="button" id="knp"
onClick="
document.vvp.points.value=
Math.round((document.vvp.volym.value/100) *
(document.vvp.kcal.value/60 + document.vvp.fett.value/9) * 10) / 10
" value="ge points" />