1

Hi why if I create a variable in my backend:

var price = 10.10;

When I render la page the var is truncate to 10.1?

<span class="form-group-field">Price: € <%=price%></span><br>
<input type="hidden" id="price" name="price" value="<%=price%>"/>
LorenzoAcc
  • 21
  • 2
  • 1
    JavaScript does not keep formatting for the numbers. If you need to represent a number in a specific way, use a string. – VLAZ Aug 27 '20 at 14:56
  • You're asking *why* it happens but if you actually want to know *how to change it*, then: [Format number to always show 2 decimal places](https://stackoverflow.com/q/6134039) – VLAZ Aug 27 '20 at 15:02

1 Answers1

0

You have to use toFixed method as javascript removes the 0's after the decimal

 var price = 10.10

 price.toFixed(2)  //it will result 10.10
Anuresh Verma
  • 818
  • 1
  • 13
  • 30