
redondear un numero a 2 decimales con switch case
Publicado por anonymous (50 intervenciones) el 30/05/2016 10:33:17
el código trata de hacer redondear un numero a 2 decimales con switch case y no me funciona y no se porque si me dicen les doy las gracias de corazon
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="content-type">
<title>triangulos</title>
</head>
<script language="JavaScript">
function rend(){
var y = document.getElementById("rend").options;
var x = document.getElementById("rend").selectedIndex;
switch (y[x].index){
case 0:
var a = document.calc.a.value;
numero2 =a * 100/100;
document.calc.a.value=numero2;
break;
case 1:
var a = document.calc.a.value;
numero3 =a * 1000/1000;
document.calc.a.value=numero3;
break;
}}
</script>
<body>
<form name="calc">
<select id="rend">
<option>2 decimales</option>
<option>3 decimales</option>
</select>
cambiar a decimales:<input name="a">
<br>
<input value="Calcular" onclick="rend()" type="button">
</form>
</body>
</html>
Valora esta pregunta


0