Skip to content

Commit 6abfa75

Browse files
author
Chris Clark
committed
[FIX] Make Amount.to_human return correct results for very small numbers
1 parent 7cbac2e commit 6abfa75

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/js/ripple/amount.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ Amount.prototype.to_human = function(opts) {
842842
}
843843

844844
var isNegative = ref._value.isNegative();
845-
var valueString = ref._value.abs().toString();
845+
var valueString = ref._value.abs().toFixed();
846846
var parts = valueString.split('.');
847847
var int_part = parts[0];
848848
var fraction_part = parts.length === 2 ? parts[1] : '';

test/amount-test.js

+6
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ describe('Amount', function() {
118118
it('to human rounding edge case, precision 3, 2', function() {
119119
assert.strictEqual(Amount.from_human("0.999 XAU").to_human({precision:2}), '1.00');
120120
});
121+
it('to human very small number', function() {
122+
assert.strictEqual(Amount.from_json('12e-20/USD').to_human(), '0.00000000000000000012');
123+
});
124+
it('to human very small number with precision', function() {
125+
assert.strictEqual(Amount.from_json('12e-20/USD').to_human({precision: 20}), '0.00000000000000000012');
126+
});
121127
});
122128
describe('from_human', function() {
123129
it('empty string', function() {

0 commit comments

Comments
 (0)