title: Printing a whole number as a decimal in Javascript without rounding
body: <p>I have a simple problem to solve, I have a variable containing a double, I'm reading in another double from user input. I need to sum the two numbers and print the result to the screen. In other languages I have worked in, just the fact that it was a double would result in it printing with a decimal, even if it is a whole number. In Javascript, this is not the case.</p>
  
  <pre><code>var d = 2.0;
  console.log(d) // out is 2
  </code></pre>
  
  <p>I can force it to print a decimal by using <code>toFixed()</code>, but then it is going to round results of other input. If the result is 2.0, I want it to print "2.0" and if the result is 2.345, I want it to print "2.345".</p>
  
  <p>The solution I have right now is to convert it to a string if it is a whole number:</p>
  
  <pre><code>var d2 = 4.0
  console.log((d2 % 1 == 0) ? d2+".0" : d2) // out is 4.0
  </code></pre>
  
  <p>I feel like there must be some better way to do this. This seems very clunky to me. I've been searching for solutions, but everything I have found so far uses <code>toFixed()</code> or some other rounding. </p>