I want to convert all mas in a string in points and vice-versa. However I don't know how to do it since I get all mas or points after the first change.
"1.000,20" should bee "1,000.20"
How can this be done?
I want to convert all mas in a string in points and vice-versa. However I don't know how to do it since I get all mas or points after the first change.
"1.000,20" should bee "1,000.20"
How can this be done?
Share Improve this question edited Jan 20, 2012 at 0:58 lisovaccaro asked Jan 20, 2012 at 0:51 lisovaccarolisovaccaro 34.1k99 gold badges271 silver badges423 bronze badges2 Answers
Reset to default 9Try
"1.000,20".replace(/[\.,]/g, function (m) { return m == '.' ? ',' : '.' })
which uses the callback function option of replace()
Try this:
var str = "1,000.20";
//Split into ponents based on a period
var ponents = str.split('.');
//Iterate through each ponent, replacing mas with periods
var length = ponents.length;
for (var i = 0; i < length; i++) {
ponents[i] = ponents[i].replace(",", ".");
}
//Array.join can be slow but still useful - join with mas
str = ponents.join(",");
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745118643a4612283.html
评论列表(0条)