* fixed decimal format in format method

* removed unnecessary condition in toPercent method
This commit is contained in:
Tobi Schäfer 2006-07-18 08:24:59 +00:00
parent 29407f6444
commit f2cc5103b4

View file

@ -9,9 +9,9 @@
* Copyright 1998-2006 Helma Software. All Rights Reserved. * Copyright 1998-2006 Helma Software. All Rights Reserved.
* *
* $RCSfile: Number.js,v $ * $RCSfile: Number.js,v $
* $Author: hannes $ * $Author: czv $
* $Revision: 1.5 $ * $Revision: 1.2 $
* $Date: 2006/04/18 13:06:58 $ * $Date: 2006/04/24 07:02:17 $
*/ */
@ -41,8 +41,8 @@ Number.Sorter.DESC = -1;
*/ */
Number.prototype.format = function(fmt) { Number.prototype.format = function(fmt) {
var df = fmt ? new java.text.DecimalFormat(fmt) var df = fmt ? new java.text.DecimalFormat(fmt)
: new java.text.DecimalFormat("#,##0.00"); : new java.text.DecimalFormat("###,##0.##");
return df.format(0+this); return df.format(0 + this); // addition with 0 prevents exception
}; };
@ -54,9 +54,9 @@ Number.prototype.format = function(fmt) {
* @return Int Percentage * @return Int Percentage
*/ */
Number.prototype.toPercent = function(total, fmt) { Number.prototype.toPercent = function(total, fmt) {
var p = this / (total / 100); if (!total)
if (!fmt) return (0).format(fmt);
return Math.round(p * 100) / 100; var p = this / (total / 100);
return p.format(fmt); return p.format(fmt);
}; };