3

Sample Example:

var amount = 100; 
alert(amount);  // output: 100

How can i achieve output as 100.0?

Santosh Jadi
  • 1,401
  • 6
  • 28
  • 52

3 Answers3

8

use .toFixed(int):

var amount = 100;
document.querySelector('pre').innerHTML = parseFloat(amount).toFixed(1);
<pre></pre>
Jai
  • 72,925
  • 12
  • 73
  • 99
4
var amount = 100;
alert(amount.toFixed(1));  // output: 100.0
alert(amount.toFixed(2));  // output: 100.00
alert(amount.toFixed(3));  // output: 100.000
Santosh Jadi
  • 1,401
  • 6
  • 28
  • 52
3
var amount = 100;
alert(amount);  // output: 100
alert(amount.toFixed(1));  // output: 100.0
alert(amount.toFixed(2));  // output: 100.00
alert(amount.toFixed(3));  // output: 100.000

https://www.w3schools.com/jsref/jsref_tofixed.asp

**number.toFixed(x)**

where number is what you intend to convert to double, and X is the precision you want to set.

Lekens
  • 1,489
  • 13
  • 28