numbers
Out of context: Reply #14
- Started
- Last post
- 17 Responses
- neverblink0
;)
function prettyLargeNumber(num,lang){
// set language specific seperators
if(lang=="EN"){
seperator = ",";
decSep = ".";
}else{
seperator = ".";
decSep = ",";
}var out = "";
var inp = num.toString();// check to see if there are decimals
var comma = inp.indexOf(decSep);
if(comma!=-1){
var decimals = inp.substr(comma);
var inp = inp.substr(0,comma);
}// add seperator at 3 digit intervals from the back
var numLength = inp.length;
while(3<numLength){
out = seperator + inp.substring(numLength-3,numLen... + out;
numLength = numLength-3;
}// add first digits to string (less then three)
out = inp.substring(0,numLength) + out;// if there were decimals add them to string
if(decimals){
out += decimals;
}return out;
}- could be rewritten to be only four lines, but I had this lying around and didn't want to botherneverblink