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
|
/// end of legacy
|
||||||
|
|
||||||
function numberShorten (Value,Accuricy) {
|
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"]) {
|
||||||
var level = 0;
|
value = !isNaN(value) ? value : 0;
|
||||||
var number = "number" == typeof Value ? Value : 0;
|
factor = !isNaN(factor) ? factor : 1000;
|
||||||
var places = "number" == typeof Accuricy ? Math.pow(10,Accuricy) : 1000;
|
accuricy = !isNaN(accuricy) ? accuricy : 3;
|
||||||
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"];
|
if (value < factor) { return value.toPrecision(acc); }
|
||||||
while (999<number) {
|
var mag = 0;
|
||||||
level++;
|
while (value > factor) {
|
||||||
number = Math.round(number)/1000;
|
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
|
/// more legacy functions that are being kept purely for backwards compatability
|
||||||
|
Loading…
x
Reference in New Issue
Block a user