From 07b8ae1437edc88601377d52965a16fcfae9555d Mon Sep 17 00:00:00 2001 From: zhaohuihua Date: Sat, 18 Apr 2020 22:45:41 +0800 Subject: [PATCH] BUG for call from Number.prototype.anyMethod Expect to use Decimal.prototype.toFixed replace the original method ```javascript (function() { var originalToFixed = Number.prototype.toFixed; Number.prototype.toFixed = function(decimal) { if (window.Decimal && Decimal.prototype.toFixed) { return new Decimal(this).toFixed(decimal); } else { return originalToFixed(this, decimal); } }; )(); ``` TestCode (2).toFixed(2); will be run to line 4340 thrown error '[DecimalError] Invalid argument: 2' because line 4290 test typeof v returned 'object' --- decimal.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/decimal.js b/decimal.js index 23cc2d3..252cc95 100644 --- a/decimal.js +++ b/decimal.js @@ -4289,7 +4289,7 @@ t = typeof v; - if (t === 'number') { + if (t === 'number' || v instanceof Number) { if (v === 0) { x.s = 1 / v < 0 ? -1 : 1; x.e = 0;