简体   繁体   English

为什么 parseFloat.replace 不是 function?

[英]Why parseFloat.replace is not a function?

If I write如果我写

console.log(parseFloat(123.123).replace(/,./g, ''))

It return它返回

Uncaught TypeError: parseFloat(...).replace is not a function

But if I write但是如果我写

console.log(parseFloat(123.123).toFixed(0).replace(/,./g, ''))

It works.有用。 So why parseFloat need toFixed to use replace()?那么为什么parseFloat需要toFixed才能使用replace()呢? Thanks谢谢

toFixed(0) convert a Number to String type. toFixed(0) 将数字转换为字符串类型。 Number prototype don't have replace method when String jas字符串 jas 时,数字原型没有替换方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM