Updated numberShorted to newer, cleaner function
This commit is contained in:
parent
99b366266a
commit
006f6e5ade
@ -87,16 +87,19 @@ function titledContainer (ParentID,ID,Class,Element,Position,Title) {
|
||||
}
|
||||
/// end of legacy
|
||||
|
||||
function numberShorten (Value,Accuricy) {
|
||||
var level = 0;
|
||||
var number = "number" == typeof Value ? Value : 0;
|
||||
var places = "number" == typeof Accuricy ? Math.pow(10,Accuricy) : 1000;
|
||||
var unit = ["","k","M","B","T","q","Q","s","S","O","N","d","Ud","Dd","Td","qd","Qd","sd","Sd","Od","Nd","v","Uv","Dv","Tv","qv","Qv","sv","Sv","Ov","Nv","t","Ut","Dt","Tt","qt","Qt","st","St","Ot","Nv","c","uc","dc","Tc","Dc","Uc","vc","Sc","Oc","Nc","STOP"];
|
||||
while (999<number) {
|
||||
level++;
|
||||
number = Math.round(number)/1000;
|
||||
function numberShorten (value=0, accuricy=3, factor=1000, notationArray=["","k","M","B","T","q","Q","s","S","O","N","d","Ud","Dd","Td","qd","Qd","sd","Sd","Od","Nd","v","Uv","Dv","Tv","qv","Qv","sv","Sv","Ov","Nv","t","Ut","Dt","Tt","qt","Qt","st","St","Ot","Nv","c","uc","dc","Tc","Dc","Uc","vc","Sc","Oc","Nc","STOP"]) {
|
||||
value = !isNaN(value) ? value : 0;
|
||||
factor = !isNaN(factor) ? factor : 1000;
|
||||
accuricy = !isNaN(accuricy) ? accuricy : 3;
|
||||
if (value < factor) { return value.toPrecision(acc); }
|
||||
var mag = 0;
|
||||
while (value > factor) {
|
||||
value /= factor;
|
||||
mag++;
|
||||
}
|
||||
return (Math.floor(number*places)/places)+unit[level];
|
||||
notationArray = Array.isArray(notationArray) ? notationArray : [""];
|
||||
if (mag > notationArray.length) { return (Math.pow(factor,mag)*value).toExponential(accuricy); }
|
||||
return value.toPrecision(accuricy)+notationArray[mag];
|
||||
}
|
||||
|
||||
/// more legacy functions that are being kept purely for backwards compatability
|
||||
|
Loading…
x
Reference in New Issue
Block a user