Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Here you go, another JavaScript approach, originally posted on SOSO:

function getRepString (rep) {

  rep = rep+''; // coerce to string

  if (rep < 1000) { // return the same number
    return rep; 
  }

  if (rep < 10000) { // place a comma between
  
    return rep.charAt(0) + ',' + rep.substring(1);
  } 

  // divide and format
  return (rep/1000).toFixed(rep % 1000 != 0)+'k';

}

Check the output results here.

Here you go, another JavaScript approach, originally posted on SO:

function getRepString (rep) {

  rep = rep+''; // coerce to string

  if (rep < 1000) { // return the same number
    return rep; 
  }

  if (rep < 10000) { // place a comma between
  
    return rep.charAt(0) + ',' + rep.substring(1);
  } 

  // divide and format
  return (rep/1000).toFixed(rep % 1000 != 0)+'k';

}

Check the output results here.

Here you go, another JavaScript approach, originally posted on SO:

function getRepString (rep) {

  rep = rep+''; // coerce to string

  if (rep < 1000) { // return the same number
    return rep; 
  }

  if (rep < 10000) { // place a comma between
  
    return rep.charAt(0) + ',' + rep.substring(1);
  } 

  // divide and format
  return (rep/1000).toFixed(rep % 1000 != 0)+'k';

}

Check the output results here.

removed some redundant code and introduced some whitespace. this is not a .js file ;-)
Source Link
Sky Sanders
  • 12.1k
  • 3
  • 32
  • 60

Here you go, another JavaScript approach, originally posted on SO:

function getRepString (rep) { 

  rep = rep+''; // coerce to string 

  if (rep < 1000) {
    return rep; // return the same number
    return rep; 
  } 

 else if (rep < 10000) { // place a comma between
  
    return rep.charAt(0) + ',' + rep.substring(1);
  } else 

 { // divide and format
    return (rep/1000).toFixed(rep % 1000 != 0)+'k';
  }
}

Check the output results here.

Here you go, another JavaScript approach, originally posted on SO:

function getRepString (rep) {
  rep = rep+''; // coerce to string
  if (rep < 1000) {
    return rep; // return the same number
  } else if (rep < 10000) { // place a comma between
    return rep.charAt(0) + ',' + rep.substring(1);
  } else { // divide and format
    return (rep/1000).toFixed(rep % 1000 != 0)+'k';
  }
}

Check the output results here.

Here you go, another JavaScript approach, originally posted on SO:

function getRepString (rep) { 

  rep = rep+''; // coerce to string 

  if (rep < 1000) { // return the same number
    return rep; 
  } 

  if (rep < 10000) { // place a comma between
  
    return rep.charAt(0) + ',' + rep.substring(1);
  }  

  // divide and format
  return (rep/1000).toFixed(rep % 1000 != 0)+'k';

}

Check the output results here.

Source Link

Here you go, another JavaScript approach, originally posted on SO:

function getRepString (rep) {
  rep = rep+''; // coerce to string
  if (rep < 1000) {
    return rep; // return the same number
  } else if (rep < 10000) { // place a comma between
    return rep.charAt(0) + ',' + rep.substring(1);
  } else { // divide and format
    return (rep/1000).toFixed(rep % 1000 != 0)+'k';
  }
}

Check the output results here.