TypeError: Cannot mix BigInt and other types, use explicit conversions
TypeError: Cannot mix BigInt and other types, use explicit conversions
我正在尝试生成一个 20 位随机数:
let code = Math.floor(10000000000000000000n + Math.random() * 90000000000000000000n)
我试过将数字放在 BigInt()
中并在后面添加 n
但仍然出现此错误。
Uncaught TypeError: Cannot mix BigInt and other types, use explicit conversions
// An operation with a fractional result will be truncated when used with a BigInt.
const rounded = 5n / 2n
// ↪ 2n, not 2.5n
// BigInt value can only operator with same type
// random BigInt
BigInt(Math.floor(Math.random() * 10))
// generate a 20 digit random number
BigInt(Math.floor(Math.random() * 100000000000000000000))
你可以查看this
我正在尝试生成一个 20 位随机数:
let code = Math.floor(10000000000000000000n + Math.random() * 90000000000000000000n)
我试过将数字放在 BigInt()
中并在后面添加 n
但仍然出现此错误。
Uncaught TypeError: Cannot mix BigInt and other types, use explicit conversions
// An operation with a fractional result will be truncated when used with a BigInt.
const rounded = 5n / 2n
// ↪ 2n, not 2.5n
// BigInt value can only operator with same type
// random BigInt
BigInt(Math.floor(Math.random() * 10))
// generate a 20 digit random number
BigInt(Math.floor(Math.random() * 100000000000000000000))
你可以查看this