1
0
Fork 0
forked from 0x2620/oxjs

improving listmap

This commit is contained in:
rolux 2011-05-22 14:39:57 +02:00
commit 5915acd72c
12 changed files with 152 additions and 39 deletions

View file

@ -2043,7 +2043,9 @@ Ox.formatArea <f> Formats a number of meters as square kilometers
@*/
Ox.formatArea = function(num, dec) {
return Ox.formatNumber(Ox.round(num / 1000000, dec)) + ' km\u00B2';
var km = num >= 1000000;
return Ox.formatNumber((km ? num / 1000000 : num).toPrecision(8)) +
' ' + (km ? 'k' : '') + 'm\u00B2';
}
/*@
@ -2271,14 +2273,15 @@ Ox.formatNumber <f> Formats a number with thousands separators
"123,456,789.000"
> Ox.formatNumber(-2000000 / 3, 3)
"-666,666.667"
> Ox.formatNumber(666666.666)
> Ox.formatNumber(666666.666, 0)
"666,667"
@*/
Ox.formatNumber = function(num, dec) {
// fixme: specify decimal and thousands separators
var str = Math.abs(num).toFixed(dec || 0),
spl = str.split('.'),
arr = [];
var arr = [],
abs = Math.abs(num),
str = Ox.isUndefined(dec) ? abs.toString() : abs.toFixed(dec),
spl = str.split('.');
while (spl[0]) {
arr.unshift(spl[0].substr(-3));
spl[0] = spl[0].substr(0, spl[0].length - 3);