Nodejs Int Format formatInt(rate)

Here you can find the source of formatInt(rate)

Method Source Code

// ======================================================================
// formats a given int value to human readable si format
// ======================================================================
var formatInt = function(rate) {
    rate = parseFloat(rate);/*  w  ww .  j a  va  2 s. co  m*/
    unit = '';
    if (rate >= 1000) { rate /= 1000; unit = 'k'; }
    if (rate >= 1000) { rate /= 1000; unit = 'M'; }
    if (rate >= 1000) { rate /= 1000; unit = 'G'; }
    if (rate >= 1000) { rate /= 1000; unit = 'T'; }
    
    return ((unit == '' ? rate.toFixed(0) : rate.toFixed(2)) + unit);
}

Related

  1. formatSpeed(bytesSec)
    function formatSpeed(bytesSec) {
      if (bytesSec > 1024*1024) {
        return Math.round(bytesSec/1024/1024*10)/10+"MB/s";
      if (bytesSec > 1024) {
        return Math.round(bytesSec/1024*10)/10+"KB/s";
      else {
        return Math.round(bytesSec*10)/10+"B/s";
    ...