문제

the following code is a converter from euro to dollar in JS. It is a JS function. eingabe = input, ausgabe = output. If I execute this code I get ,,,,,,,, as an output instead of 1,37.

eingabe = eingabe.replace(/,/g, ".");
eingabe = parseFloat(eingabe);
var kurs_euro = 1.37 // 1 euro = 1,37 dollar
var ausgabe = 0;
ausgabe = eingabe * kurs_euro;
ausgabe = Math.round((ausgabe + 0.00001) * 100)/100 + " Dollar";
ausgabe = ausgabe.toString();
ausgabe = ausgabe.replace(/./g, ",");
alert(ausgabe);
도움이 되었습니까?

해결책

/./ means that you use regex and . replaces any character. Try without regex:

ausgabe.replace('.', ',');

Or escape .:

ausgabe.replace(/\./g, ',');
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top