Я написал этот код, и когда я его выполняю, он показывает до 10 знаков после запятой. Мне было интересно, есть ли способ удалить лишние десятичные знаки.
Теперь я попробовал это:
price = price.tofixed (2);
но похоже, это не работает, и я не понимаю, почему.
<script>
var weight = parseFloat(prompt("weight in lbs", "10"));
weight = weight.toFixed(2);
var price;
price= price.tofixed(2);
// writes down the volumes of triangles-->
document.write("<p>the weight is : "+weight+"</p>");
</script>
<script>
// else if statements which will calculate the price of the shipping -->
if(weight <= 2) price=weight*1.10;
else if (weight>=2 && weight<=6) price=weight*2.20;
else if(weight>6 && weight<=10) price=weight*3.70;
else if(weight>10) price=weight*3.80;
document.write("<p>the price of the item's shipping is "+price+"</p>");
</script>
</script>
</body>
</html>