JavaScript-MochiKit
view release on metacpan or search on metacpan
lib/JavaScript/MochiKit/JS/Format.pm view on Meta::CPAN
MochiKit.Format.__repr__ = function () {
return "[" + this.NAME + " " + this.VERSION + "]";
};
MochiKit.Format.toString = function () {
return this.__repr__();
};
MochiKit.Format._numberFormatter = function (placeholder, header, footer, locale, isPercent, precision, leadingZeros, separatorAt, trailingZeros) {
return function (num) {
num = parseFloat(num);
if (typeof(num) == "undefined" || num == null || isNaN(num)) {
return placeholder;
}
var curheader = header;
var curfooter = footer;
if (num < 0) {
num = -num;
} else {
curheader = curheader.replace(/-/, "");
}
var me = arguments.callee;
lib/JavaScript/MochiKit/JS/Format.pm view on Meta::CPAN
return locale;
}
};
MochiKit.Format.twoDigitAverage = function (numerator, denominator) {
/***
Calculate an average from a numerator and a denominator and return
it as a string with two digits of precision (e.g. "1.23").
If the denominator is 0, "0" will be returned instead of NaN.
***/
if (denominator) {
var res = numerator / denominator;
if (!isNaN(res)) {
return MochiKit.Format.twoDigitFloat(numerator / denominator);
}
}
return "0";
};
MochiKit.Format.twoDigitFloat = function (someFloat) {
/***
Roughly equivalent to: sprintf("%.2f", someFloat)
( run in 0.222 second using v1.01-cache-2.11-cpan-fd5d4e115d8 )