Javascript Regex: replacing the last dot for a comma

前端 未结 5 1003
情歌与酒
情歌与酒 2021-01-05 20:38

I have the following code:

var x = \"100.007\"
x = String(parseFloat(x).toFixed(2));
return x
=> 100.01

This works awesomely just how I

5条回答
  •  春和景丽
    2021-01-05 21:33

    You can use lastIndexOf to find the last occurence of ,. Then you can use slice to put the part before and after the , together with a . inbetween.

提交回复
热议问题