Javascript Regex: replacing the last dot for a comma
问题 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 want it to work. I just want a tiny addition, which is something like: var x = "100,007" x.replace(",", ".") x.replace x = String(parseFloat(x).toFixed(2)); x.replace(".", ",") return x => 100,01 However, this code will replace the first occurrence of the ",", where I want to catch the last one. Any help would be appreciated. 回答1: You can do it with a regular