链接到javascript中的强制类型
是否可以缩短上述类型的铸件 如果我这样做链接到javascript中的强制类型,javascript,Javascript,是否可以缩短上述类型的铸件 如果我这样做 let finalPrice = room.points[0].price.finalPrice //string finalPrice = +finalPrice //number finalPrice = finalPrice.toFixed(2) //2 decimal 我将得到以下错误:toFixed不是这样的函数: +room.points[0].price.finalPrice.toFixed(2) 不需要中间变量 +的
let finalPrice = room.points[0].price.finalPrice //string
finalPrice = +finalPrice //number
finalPrice = finalPrice.toFixed(2) //2 decimal
我将得到以下错误:toFixed不是这样的函数:
+room.points[0].price.finalPrice.toFixed(2)
不需要中间变量
+
的问题是,它的运算符优先级低于使用.toFixed
调用的
。如下所示:
+room.points[0].price.finalPrice.toFixed(2)
不需要中间变量
+
的问题在于,它的运算符优先级低于.toFixed
调用的
。(+room.points[0]。price.finalPrice)。toFixed(2)
(+room.points[0]。price.finalPrice)。toFixed(2)
(+room.points[0]。price.finalPrice)。toFixed(2)
应该这样做。(+room.points[0]。price.finalPrice)。toFixed(2)