javascript Double.parseDouble 在我的网页上不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15748099/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 01:57:54  来源:igfitidea点击:

Double.parseDouble is not working on my webpage

javascript

提问by tnbumbray

I'm trying to add some funds and I want to use Double.parseDouble but, I don't think the page is recognizing double.parseDouble. I don't get an error but it won't add or pass the values.

我正在尝试添加一些资金并且我想使用 Double.parseDouble 但是,我认为该页面无法识别 double.parseDouble。我没有收到错误,但它不会添加或传递值。

Here is my code.

这是我的代码。

function CalculateBudget(){
    var table = document.getElementById('tblBudgetTotals');
    input1600 = 0;
    input1602 = 0;
    input1603 = 0;
    input1608 = 0;
    input1612 = 0;
    funding = 0;
    budgetSum = 0;

          input1600 = Double.parseDouble(document.getElementById('txt1600').value);
    input1602 = Double.parseDouble(document.getElementById('txt1602').value);
    input1603 = Double.parseDouble(document.getElementById('txt1603').value);
    input1608 = Double.parseDouble(document.getElementById('txt1608').value);
    input1612 = Double.parseDouble(document.getElementById('txt1612').value);
    funding = Double.parseDouble(document.getElementById('FundingTotals').value);

    budgetSum += Double.parseDouble(input1600) + Double.parseDouble(input1602) + Double.parseDouble(input1603) + Double.parseDouble(input1608) + Double.parseDouble(input1612) + Double.parseDouble(funding);

    document.getElementById('totbud').value = Double.parseDouble(budgetSum);
}

回答by metadept

I think you should just be using parseFloatfor this, since according to thesethreadsall numbers in JavaScript are already "double precision" (64-bit) floats.

我认为您应该parseFloat为此使用它,因为根据这些线程,JavaScript 中的所有数字都已经是“双精度”(64 位)浮点数。