Obscurity
2015-05-09 20:42:47
Nothing major. Just thought some of yous could use it in your proggies and such. Probably a better method of doing it, but meh. Rounds to the tenth.
function int32.formatKMB(funcDecimal:int32=1):string;
begin
case self of
0..999:result:=toStr(self);
1000..999999:result:=toStr(round(self/pow(10,3-(funcDecimal:=min(3,funcDecimal))))/pow(10,funcDecimal))+'K';
1000000..999999999:result:=toStr(round(self/pow(10,6-(funcDecimal:=min(3,funcDecimal))))/pow(10,funcDecimal))+'M';
1000000000..2147483647:result:=toStr(round(self/pow(10,9-(funcDecimal:=min(3,funcDecimal))))/pow(10,funcDecimal))+'B';
end;
end;
function uInt32.formatKMB(funcDecimal:int32=1):string;
begin
case self of
0..999:result:=toStr(self);
1000..999999:result:=toStr(round(self/pow(10,3-(funcDecimal:=min(3,funcDecimal))))/pow(10,funcDecimal))+'K';
1000000..999999999:result:=toStr(round(self/pow(10,6-(funcDecimal:=min(3,funcDecimal))))/pow(10,funcDecimal))+'M';
1000000000..2147483647:result:=toStr(round(self/pow(10,9-(funcDecimal:=min(3,funcDecimal))))/pow(10,funcDecimal))+'B';
end;
end;moneyEarned:=12345678;
writeLN('You earned ',moneyEarned.formatKMB(),' GP!'); //~ "You earned 12.3M GP!"