fix number
This commit is contained in:
+36
-38
@@ -51,49 +51,47 @@ define('number', [], function () {
|
||||
_.extend(NumberUtil.prototype, {
|
||||
|
||||
formatInt: function (value) {
|
||||
if (value !== null) {
|
||||
var stringValue = value.toString();
|
||||
stringValue = stringValue.replace(/\B(?=(\d{3})+(?!\d))/g, this.getThousandSeparator());
|
||||
return stringValue;
|
||||
}
|
||||
return '';
|
||||
if (value !== null || typeof value === 'undefined') return '';
|
||||
|
||||
var stringValue = value.toString();
|
||||
stringValue = stringValue.replace(/\B(?=(\d{3})+(?!\d))/g, this.getThousandSeparator());
|
||||
return stringValue;
|
||||
},
|
||||
|
||||
formatFloat: function (value, decimalPlaces) {
|
||||
if (value !== null) {
|
||||
if (value !== null || typeof value === 'undefined') return '';
|
||||
|
||||
if (decimalPlaces === 0) {
|
||||
value = Math.round(value);
|
||||
} else if (decimalPlaces) {
|
||||
value = Math.round(value * Math.pow(10, decimalPlaces)) / (Math.pow(10, decimalPlaces));
|
||||
} else {
|
||||
value = Math.round(value * Math.pow(10, this.maxDecimalPlaces)) / (Math.pow(10, this.maxDecimalPlaces));
|
||||
}
|
||||
|
||||
var parts = value.toString().split(".");
|
||||
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, this.getThousandSeparator());
|
||||
|
||||
if (decimalPlaces === 0) {
|
||||
return parts[0];
|
||||
} else if (decimalPlaces) {
|
||||
var decimalPartLength = 0;
|
||||
if (parts.length > 1) {
|
||||
decimalPartLength = parts[1].length;
|
||||
} else {
|
||||
parts[1] = '';
|
||||
}
|
||||
|
||||
if (decimalPlaces && decimalPartLength < decimalPlaces) {
|
||||
var limit = decimalPlaces - decimalPartLength;
|
||||
for (var i = 0; i < limit; i++) {
|
||||
parts[1] += '0';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return parts.join(this.getDecimalMark());
|
||||
if (decimalPlaces === 0) {
|
||||
value = Math.round(value);
|
||||
} else if (decimalPlaces) {
|
||||
value = Math.round(value * Math.pow(10, decimalPlaces)) / (Math.pow(10, decimalPlaces));
|
||||
} else {
|
||||
value = Math.round(value * Math.pow(10, this.maxDecimalPlaces)) / (Math.pow(10, this.maxDecimalPlaces));
|
||||
}
|
||||
return '';
|
||||
|
||||
var parts = value.toString().split(".");
|
||||
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, this.getThousandSeparator());
|
||||
|
||||
if (decimalPlaces === 0) {
|
||||
return parts[0];
|
||||
} else if (decimalPlaces) {
|
||||
var decimalPartLength = 0;
|
||||
if (parts.length > 1) {
|
||||
decimalPartLength = parts[1].length;
|
||||
} else {
|
||||
parts[1] = '';
|
||||
}
|
||||
|
||||
if (decimalPlaces && decimalPartLength < decimalPlaces) {
|
||||
var limit = decimalPlaces - decimalPartLength;
|
||||
for (var i = 0; i < limit; i++) {
|
||||
parts[1] += '0';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return parts.join(this.getDecimalMark());
|
||||
|
||||
},
|
||||
|
||||
getThousandSeparator: function () {
|
||||
|
||||
Reference in New Issue
Block a user