title: javascript print tofixed and if not possible print normal
body: <p>So I have some values that should be printed as toFixed(8), but sometimes it happens that the value is a string with text and therefore everything that comes behind that (in a loop) is forgotten due to the error.</p>
  
  <p>Is there any possibility to use toFixed(8) if it can and otherwise print the var without tofixed?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$.each(trades, function(_, obj) {
    if (obj['sold'] == true) {
      if (obj['enddate'] === undefined) {
        count = 1
        profit = obj['profit_percentage']
        tradeList.add({
          startdate: obj['datetime'],
          if (typeof obj['buyprice'] === "number") {
            buyprice: obj['buyprice'].toFixed(8)
          }
          else {
            buyprice: obj['buyprice']
          }
        });
      }
    }
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>