微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用正确的 javascript 允许十进制输入?

如何解决如何使用正确的 javascript 允许十进制输入?

自从我编码以来已经有一段时间了。我已经让代码工作了。输出显示时数学是正确的,但输入只允许整数。如果我尝试输入小数,结果将不会显示任何内容。我认为解析 int 行是错误的,但我不确定用什么替换它。谢谢!等式是(比特币市值/按目标币市值)*当前币价格=每枚币的最高价格

 var numOne,numTwo,numThree,res,temp;
    function crypto()
    {
      numOne = parseInt(document.getElementById("one").value);
      numTwo = parseInt(document.getElementById("two").value);
      numThree = parseInt(document.getElementById("three").value);
      if(numOne && numTwo && numThree)
      {
        temp = document.getElementById("res");
        temp.style.display = "block";
        document.getElementById("calc").value = res;
        res = (numOne / numTwo) * numThree;
      }
    }
    <p id="input">Enter Bitcoin Marketcap: <input id="one">
    <br/><br/>
    Enter Target Marketcap: <input id="two"></p>
    Enter Current Price per One Target Coin: <input id="three"></p>
    <p><button onclick="crypto()">Calculate max price per one cryptocoin</button></p>
    <p id="res" style="display:none;">
    Price Per Coin Result = <input id="calc"><br/><br/>
    

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。