3

Sample Example:

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

How can i achieve output as 100.0?

Santosh Jadi
  • 1,479
  • 6
  • 29
  • 55

3 Answers3

8

use .toFixed(int):

var amount = 100;
document.querySelector('pre').innerHTML = parseFloat(amount).toFixed(1);
<pre></pre>
Jai
  • 74,255
  • 12
  • 74
  • 103
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,479
  • 6
  • 29
  • 55
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,823
  • 17
  • 31