title: Parse number to exact 2 decimal place with output type as number or float in javascript
body: <p>I'm trying to parse a number in JavaScript to exact 2 decimals for all kinds of input values.<br>
  for Eg.  </p>
  
  <pre><code>input = 631, required output = 631.00, type = float
  input = 631.3, required output = 631.30, type = float
  input = 631.333, required output = 631.33, type = float
  </code></pre>
  
  <p>I tried as below options  </p>
  
  <pre><code>input = 631  
  output = parseFloat(input).toFixed(2) // '631.00'  
  </code></pre>
  
  <p>here type is coming as a string, which is not required.  </p>
  
  <pre><code>input = 631.3  
  output = parseFloat(input) // 631.3  
  </code></pre>
  
  <p>I want it to be exact 2 decimals  </p>
  
  <p>I also tried <code>num.toPrecision(totalDigits)</code>, but it requires total digits to be required.  </p>
  
  <p>API call</p>
  
  <pre><code>curl -X POST \
    https://www.wepay.in.th/client_api.php \
    -H 'cache-control: no-cache' \
    -H 'content-type: application/x-www-form-urlencoded' \
    -d 'username=xxxxx&amp;password=xxxxxx&amp;json=true&amp;resp_url=https%3A%2F%2Fapi.witpay.co.th%2Fproccesswepay&amp;pay_to_ref3=&amp;pay_to_barcode1=&amp;type=mtopup&amp;pay_to_company=12CALL&amp;pay_to_ref2=&amp;pay_to_ref1=0929418926&amp;dest_ref=34&amp;pay_to_amount=10.00'
  </code></pre>
  
  <p>API call in nodeJS</p>
  
  <pre><code>const params = {
    dest_ref: client_ref,
    pay_to_company: serviceCode,
    pay_to_amount: parseFloat(amount).toFixed(2),
    pay_to_ref1: payToRef1,
  }
  
  request({
    baseUrl,
    url: '/client_api.php', // URL to hit
    method: 'POST',
    form: params,
    headers: [{
      name: 'content-type',
      value: 'application/x-www-form-urlencoded',
    }],
  }, (error, response, body) =&gt; {
    // handle response and error
  })
  </code></pre>
  
  <p>PS: This is format it required from 3rd party API, so can't change it.</p>