的代碼工作是工作的罰款,直到我添加函數內部的線Math.round不會在JavaScript
parseLocalFloatCnt: num = Math.round(num*1.2);
有誰知道如何解決這個問題?由於
<!DOCTYPE html>
<html>
<body>
<p>Write something in the text field to trigger a function.</p>
<input type="text" id="myInput" oninput="myFunction()">
<p id="demo"></p>
<script>
function myFunction() {
var x = parseLocalFloatCnt(document.getElementById("myInput").value);
document.getElementById("demo").innerHTML = "You wrote: " + x;
}
function parseLocalFloatCnt(num) {
num = Math.round(num*1.2);
return +(num.replace(getLocalDecimalSeparator(), '.'));
}
function getLocalDecimalSeparator() {
var n = 1.1;
return n.toLocaleString().substring(1,2);
}
</script>
</body>
</html>
你能解釋一下你想做什麼嗎? – Grundy
在你的函數中:'Math.round'返回_Number_,你試着用'toString'替換分隔符,並再次嘗試得到相同的_Number_,但是爲什麼?如果你'返回Math.round(num * 1.2)'結果將是相同的 – Grundy
也看到這[post](http://stackoverflow.com/questions/2085275/what-is-the-decimal-separator-symbol- in-javascript) – Grundy