小数号中的JavaScript中的字符串值如何转换字符串值

发布于 2025-01-29 07:15:03 字数 54 浏览 4 评论 0原文

如何使用JavaScript将r $ 800,000.00的弦类型转换为800000小数类型?

How to convert R$ 800,000.00 in string type to 800000 decimal type using JavaScript?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

禾厶谷欠 2025-02-05 07:15:03

你为什么不使用
currenyvalueInt = parseint(currencyValuestring.split(“”)[1])

Why don’t you just use
currenyValueInt = parseInt(currencyValueString.split(" ")[1])

耀眼的星火 2025-02-05 07:15:03

您可以通过替换数字和十进制分隔符以外的所有内容来消毒字符串,然后用number()或简单地在其前面添加+表达:

let str = +"R$ 800,000.00".replace(/[^\d.]/g, '');

console.log(str, typeof str)

You sanitize the string by replacing everything but digits and the decimal separator and then cast it to a Number, either with Number() or by simply adding a + in front of the expression:

let str = +"R$ 800,000.00".replace(/[^\d.]/g, '');

console.log(str, typeof str)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文