mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Add digit group separator formatting to to_human().
This commit is contained in:
@@ -478,8 +478,15 @@ Amount.prototype.to_human = function (opts)
|
||||
{
|
||||
opts = opts || {};
|
||||
|
||||
var int_part = this._value.divide(consts.bi_xns_unit).toString(10);
|
||||
var fraction_part = this._value.mod(consts.bi_xns_unit).toString(10);
|
||||
// Default options
|
||||
if ("undefined" === typeof opts.group_sep) opts.group_sep = true;
|
||||
opts.group_width = opts.group_width || 3;
|
||||
|
||||
var denominator = this._is_native ?
|
||||
consts.bi_xns_unit :
|
||||
consts.bi_10.clone().pow(-this._offset);
|
||||
var int_part = this._value.divide(denominator).toString(10);
|
||||
var fraction_part = this._value.mod(denominator).toString(10);
|
||||
|
||||
int_part = int_part.replace(/^0*/, '');
|
||||
fraction_part = fraction_part.replace(/0*$/, '');
|
||||
@@ -488,6 +495,13 @@ Amount.prototype.to_human = function (opts)
|
||||
fraction_part = fraction_part.slice(0, opts.precision);
|
||||
}
|
||||
|
||||
if (opts.group_sep) {
|
||||
if ("string" !== typeof opts.group_sep) {
|
||||
opts.group_sep = ',';
|
||||
}
|
||||
int_part = utils.chunkString(int_part, opts.group_width, true).join(opts.group_sep);
|
||||
}
|
||||
|
||||
var formatted = '';
|
||||
formatted += int_part.length ? int_part : '0';
|
||||
formatted += fraction_part.length ? '.'+fraction_part : '';
|
||||
|
||||
Reference in New Issue
Block a user