From 7818d4deb66364892c13121931024ae1e1247507 Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Sat, 24 Mar 2012 10:39:21 +0000 Subject: [PATCH] improve Ox.formatValue --- source/Ox/js/Constants.js | 4 ++-- source/Ox/js/Format.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/source/Ox/js/Constants.js b/source/Ox/js/Constants.js index ccdc2af3..6b790e3e 100644 --- a/source/Ox/js/Constants.js +++ b/source/Ox/js/Constants.js @@ -82,8 +82,8 @@ Ox.PATH = Ox.makeArray( ).reverse().filter(function(element) { return /Ox\.js$/.test(element.src); })[0].src.replace(/Ox\.js$/, ''); -//@ Ox.PREFIXES <[str]> ['K', 'M', 'G', 'T', 'P'] -Ox.PREFIXES = ['K', 'M', 'G', 'T', 'P']; +//@ Ox.PREFIXES <[str]> ['', 'K', 'M', 'G', 'T', 'P'] +Ox.PREFIXES = ['', 'K', 'M', 'G', 'T', 'P']; //@ Ox.SEASONS <[str]> Names of the seasons of the year Ox.SEASONS = ['Winter', 'Spring', 'Summer', 'Fall']; //@ Ox.SYMBOLS Unicode characters for symbols diff --git a/source/Ox/js/Format.js b/source/Ox/js/Format.js index 12eed55e..b16f9f22 100644 --- a/source/Ox/js/Format.js +++ b/source/Ox/js/Format.js @@ -545,9 +545,9 @@ Ox.formatValue = function(num, str, bin) { len = Ox.PREFIXES.length, val; Ox.forEach(Ox.PREFIXES, function(chr, i) { - if (num < Math.pow(base, i + 2) || i == len - 1) { - val = Ox.formatNumber(num / Math.pow(base, i + 1), i) + - ' ' + chr + (bin ? 'i' : '') + str; + if (num < Math.pow(base, i + 1) || i == len - 1) { + val = Ox.formatNumber(num / Math.pow(base, i), i) + + ' ' + chr + (chr && bin ? 'i' : '') + str; return false; } });