Formats a float number into an appropriate representation - Node.js Number

Node.js examples for Number:Int

Description

Formats a float number into an appropriate representation

Demo Code


/**/*from  ww  w  .  j  a  v  a2s  .  c  o  m*/
 * Formats a float number into an appropriate representation
 * of milliseconds
 * @param  {Float} ms value to format in ms
 * @return {String}
 */
formatMs : function (ms) {
  if ( ms < 1000 ) {
    return ms.toFixed(2) + 'ms';
  } else {
    return (ms/1000).toFixed(2)+'sec';
  }
}

Related Tutorials