return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>regex - Convert currency to decimal number JavaScript - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

regex - Convert currency to decimal number JavaScript - Stack Overflow

programmeradmin2浏览0评论

How can I convert currency string like this $123,456,78.3 to number like this 12345678.3 I tried to do using this pattern

let str = "$123,456,78.3";
let newStr = str.replace(/\D/g, '');

but it replaces . too.

How can I convert currency string like this $123,456,78.3 to number like this 12345678.3 I tried to do using this pattern

let str = "$123,456,78.3";
let newStr = str.replace(/\D/g, '');

but it replaces . too.

Share Improve this question asked Aug 9, 2020 at 0:03 DerenikDerenik 531 silver badge6 bronze badges 1
  • Just pasting your subject in web search returns lots of results that should have enabled you to find solutions – charlietfl Commented Aug 9, 2020 at 0:14
Add a ment  | 

3 Answers 3

Reset to default 3
var str = "$123,456,78.3";
var newStr = Number(str.replace(/[^0-9.-]+/g,""));

Use a lowercase d, and put it into a negated character group along with the ..

let str = "$123,456,78.3";
let newStr = str.replace(/[^\d.]/g, '');

console.log(newStr)

You can use a negative character group:

"$123,456,78.3".replace(/[^\d.]/g, "")
发布评论

评论列表(0)

  1. 暂无评论