toFixed 不是函数?
toFixed is not a function?
我的代码出现错误,以前从未遇到过,这真的很奇怪。
我确实尝试过 parseFloat 但这也没有用..
代码:https://gist.github.com/markd69/aca03cab20e46e0abae7d4f1e402092d
You have triggered an unhandledRejection, you may have forgotten to catch a
Promise rejection:
TypeError: (((0.044000000000000004 * args[0]) + 0.3) + args[0]).toFixed is
not a
function
at Object.exports.run (/root/athex/athex-bot/commands/pay.js:12:54)
at Client.bot.on (/root/athex/athex-bot/index.js:316:11)
at emitOne (events.js:116:13)
at Client.emit (events.js:211:7)
at MessageCreateHandler.handler
这与 args[0]
具有 String
的值有关。
以args[0]
为字符串:
(0.044000000000000004 * args[0]) + 0.3)
结果是 Number
.
((0.044000000000000004 * args[0]) + 0.3) + args[0]
结果为 String
.
.toFixed
仅在 Number
对象上找到,因此这会导致 ... is not a function
错误。
将 args[0]
转换为 Number
并使用它可以解决问题:
var num = Number(args[0]);
return (((0.044000000000000004 * num) + 0.3) + num).toFixed();
我的代码出现错误,以前从未遇到过,这真的很奇怪。 我确实尝试过 parseFloat 但这也没有用.. 代码:https://gist.github.com/markd69/aca03cab20e46e0abae7d4f1e402092d
You have triggered an unhandledRejection, you may have forgotten to catch a
Promise rejection:
TypeError: (((0.044000000000000004 * args[0]) + 0.3) + args[0]).toFixed is
not a
function
at Object.exports.run (/root/athex/athex-bot/commands/pay.js:12:54)
at Client.bot.on (/root/athex/athex-bot/index.js:316:11)
at emitOne (events.js:116:13)
at Client.emit (events.js:211:7)
at MessageCreateHandler.handler
这与 args[0]
具有 String
的值有关。
以args[0]
为字符串:
(0.044000000000000004 * args[0]) + 0.3)
结果是Number
.((0.044000000000000004 * args[0]) + 0.3) + args[0]
结果为String
.
.toFixed
仅在 Number
对象上找到,因此这会导致 ... is not a function
错误。
将 args[0]
转换为 Number
并使用它可以解决问题:
var num = Number(args[0]);
return (((0.044000000000000004 * num) + 0.3) + num).toFixed();