diff --git a/lib/function/string/format.js b/lib/function/string/format.js index 5ad15b450..a20773530 100644 --- a/lib/function/string/format.js +++ b/lib/function/string/format.js @@ -38,10 +38,10 @@ function factory (type, config, load, typed) { * - `precision: number` * A number between 0 and 16 to round the digits of the number. In case * of notations 'exponential' and 'auto', `precision` defines the total - * number of significant digits returned and is undefined by default. + * number of significant digits returned. * In case of notation 'fixed', `precision` defines the number of - * significant digits after the decimal point, and is undefined by default, - * not rounding any digits. + * significant digits after the decimal point. + * `precision` is undefined by default. * - `exponential: Object` * An object containing two parameters, {number} lower and {number} upper, * used by notation 'auto' to determine when to return exponential diff --git a/lib/utils/bignumber/formatter.js b/lib/utils/bignumber/formatter.js index 664625ec5..29f9a2795 100644 --- a/lib/utils/bignumber/formatter.js +++ b/lib/utils/bignumber/formatter.js @@ -29,14 +29,12 @@ * the digits of the number. * In case of notations 'exponential' and * 'auto', `precision` defines the total - * number of significant digits returned - * and is undefined by default. + * number of significant digits returned. * In case of notation 'fixed', * `precision` defines the number of * significant digits after the decimal - * point, and is undefined by default, - * not rounding any digits. - * point, and is 0 by default. + * point. + * `precision` is undefined by default. * {Object} exponential An object containing two parameters, * {number} lower and {number} upper, * used by notation 'auto' to determine @@ -176,11 +174,9 @@ exports.toExponential = function (value, precision) { /** * Format a number with fixed notation. * @param {BigNumber} value - * @param {number} [precision=0] Optional number of decimals after the - * decimal point. Zero by default. + * @param {number} [precision=undefined] Optional number of decimals after the + * decimal point. Undefined by default. */ exports.toFixed = function (value, precision) { - return value.toFixed(precision || 0); - // Note: the (precision || 0) is needed as the toFixed of BigNumber has an - // undefined default precision instead of 0. + return value.toFixed(precision); }; diff --git a/lib/utils/number.js b/lib/utils/number.js index 3d4097aed..3a5c791e5 100644 --- a/lib/utils/number.js +++ b/lib/utils/number.js @@ -75,14 +75,13 @@ exports.sign = Math.sign || function(x) { * the digits of the number. * In case of notations 'exponential' and * 'auto', `precision` defines the total - * number of significant digits returned - * and is undefined by default. + * number of significant digits returned. * In case of notation 'fixed', * `precision` defines the number of * significant digits after the decimal - * point, and is undefined by default, + * point. + * `precision` is undefined by default, * not rounding any digits. - * point, and is 0 by default. * {Object} exponential An object containing two parameters, * {number} lower and {number} upper, * used by notation 'auto' to determine diff --git a/test/utils/bignumber/formatter.test.js b/test/utils/bignumber/formatter.test.js index b35ead661..f1e906e97 100644 --- a/test/utils/bignumber/formatter.test.js +++ b/test/utils/bignumber/formatter.test.js @@ -189,8 +189,8 @@ describe('format', function () { notation: 'fixed' }; - assert.deepEqual(formatter.format(new BigNumber('1.23456'), options), '1'); - assert.deepEqual(formatter.format(new BigNumber('1.7'), options), '2'); + assert.deepEqual(formatter.format(new BigNumber('1.23456'), options), '1.23456'); + assert.deepEqual(formatter.format(new BigNumber('1.7'), options), '1.7'); assert.deepEqual(formatter.format(new BigNumber('12345678'), options), '12345678'); assert.deepEqual(formatter.format(new BigNumber('12e18'), options), '12000000000000000000'); assert.deepEqual(formatter.format(new BigNumber('12e30'), options), '12000000000000000000000000000000'); @@ -219,7 +219,7 @@ describe('format', function () { it('should format a bignumber using toFixed', function() { var Big = BigNumber.clone({precision: 100}); - assert.equal(formatter.toFixed(new Big(2.34)), '2'); + assert.equal(formatter.toFixed(new Big(2.34)), '2.34'); assert.equal(formatter.toFixed(new Big(2.34), 1), '2.3'); assert.equal(formatter.toFixed(new Big(2), 20), '2.00000000000000000000'); assert.equal(formatter.toFixed(new Big(2), 21), '2.000000000000000000000');