This repository has been archived by the owner on Feb 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from StellarCN/develop
trade bug
- Loading branch information
Showing
19 changed files
with
258 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// toFixed兼容方法 | ||
Number.prototype.toFixed = function (n) { | ||
if (n > 20 || n < 0) { | ||
throw new RangeError('toFixed() digits argument must be between 0 and 20'); | ||
} | ||
const number = this; | ||
if (isNaN(number) || number >= Math.pow(10, 21)) { | ||
return number.toString(); | ||
} | ||
if (typeof (n) == 'undefined' || n == 0) { | ||
return (Math.round(number)).toString(); | ||
} | ||
|
||
let result = number.toString(); | ||
const arr = result.split('.'); | ||
|
||
// 整数的情况 | ||
if (arr.length < 2) { | ||
result += '.'; | ||
for (let i = 0; i < n; i += 1) { | ||
result += '0'; | ||
} | ||
return result; | ||
} | ||
|
||
const integer = arr[0]; | ||
const decimal = arr[1]; | ||
if (decimal.length == n) { | ||
return result; | ||
} | ||
if (decimal.length < n) { | ||
for (let i = 0; i < n - decimal.length; i += 1) { | ||
result += '0'; | ||
} | ||
return result; | ||
} | ||
result = integer + '.' + decimal.substr(0, n); | ||
const last = decimal.substr(n, 1); | ||
|
||
// 四舍五入,转换为整数再处理,避免浮点数精度的损失 | ||
if (parseInt(last, 10) >= 5) { | ||
const x = Math.pow(10, n); | ||
result = (Math.round((parseFloat(result) * x)) + 1) / x; | ||
result = result.toFixed(n); | ||
} | ||
|
||
return result; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.