OVH Cloud OVH Cloud

Calculs :-(

1 réponse
Avatar
loiseauthierry
<html>
<head>
<title>Test calculs en JS</title>
</head>
<body>
<script type="text/javascript">
a=10.2;
b=4.9;
alert(a-b);
</script>
10.2-4.9 en JS ?
</body>
</html>

Ca devrait donner 5.3, non ?

Et ben non !

Je suppose que JS fait alors un calcul intrinsèque en hexa ...

Thierry
--
<http://www.trombinewtscope.free.fr/> <http://astrophoto.free.fr/>
<http://ecm.terrasson.free.fr/> <http://gerry.garstein.free.fr/>
<http://signe.furax.free.fr/>

1 réponse

Avatar
ASM
<script type="text/javascript">
a.2;
b=4.9;
alert(a-b);
</script>

Ca devrait donner 5.3, non ?

Et ben non !


he ben si :

alert((a*10-b*10)/10);

Je suppose que JS fait alors un calcul intrinsèque en hexa ...


se méfier des approximations avec les flottants


--
Stephane Moriaux et son [moins] vieux Mac