Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将值转换为整数十进制_Javascript_Web_Asp Classic - Fatal编程技术网

Javascript 将值转换为整数十进制

Javascript 将值转换为整数十进制,javascript,web,asp-classic,Javascript,Web,Asp Classic,嗨,我真的需要你的帮助 目前我用这段代码做自动计算 但后来我得到了8.74999999998作为答案 我尝试使用fixed to two,但仍然得到了相同的答案 <span name="epr_fctot" id="epr_fctot" class="medium" size="15"> <script type="text/javascript"> function fcFunction() { var fc_airticket =parseFloat(docum

嗨,我真的需要你的帮助

目前我用这段代码做自动计算

但后来我得到了8.74999999998作为答案 我尝试使用fixed to two,但仍然得到了相同的答案

<span name="epr_fctot"  id="epr_fctot" class="medium" size="15">
<script  type="text/javascript">
function fcFunction() {

var fc_airticket =parseFloat(document.getElementById("fc_airticket").value)
var fc_accomodation =parseFloat(document.getElementById("fc_accomodation").value)
var fc_allowance = parseFloat(document.getElementById("fc_allowance").value)
var fc_transport = parseFloat(document.getElementById("fc_transport").value)
var fc_entertainment =parseFloat(document.getElementById("fc_entertainment").value)
var fc_other = parseFloat(document.getElementById("fc_other").value)

var x = parseFloat(fc_airticket) + parseFloat(fc_accomodation)+parseFloat(fc_allowance)+ parseFloat(fc_transport)+parseFloat(fc_entertainment)+ parseFloat(fc_other);

document.getElementById("epr_fctot").innerHTML = x


}
</script>

</span></label></td>

函数fcFunction(){
var fc_airticket=parseFloat(document.getElementById(“fc_airticket”).value)
var fc_accountation=parseFloat(document.getElementById(“fc_accountation”).value)
var fc_allowment=parseFloat(document.getElementById(“fc_allowment”).value)
var fc_transport=parseFloat(document.getElementById(“fc_transport”).value)
var fc_entertainment=parseFloat(document.getElementById(“fc_entertainment”).value)
var fc_other=parseFloat(document.getElementById(“fc_other”).value)
var x=帕斯浮动(fc_机票)+帕斯浮动(fc_住宿)+帕斯浮动(fc_津贴)+帕斯浮动(fc_交通)+帕斯浮动(fc_娱乐)+帕斯浮动(fc_其他);
document.getElementById(“epr_fctot”).innerHTML=x
}
你可以这样试试。。 弦乐-

var twoPlacedFloat = parseFloat(x).toFixed(2);
对于数字,我做了一个函数

Number.prototype.round = function(num) {
 num= num || 10;
  return parseFloat( this.toFixed(num) );
};
根据你的情况申请-

x.round(2)
编辑 你也可以试试这个

Math.round(x * 100) / 100
你可以那样试试。。 弦乐-

var twoPlacedFloat = parseFloat(x).toFixed(2);
对于数字,我做了一个函数

Number.prototype.round = function(num) {
 num= num || 10;
  return parseFloat( this.toFixed(num) );
};
根据你的情况申请-

x.round(2)
编辑 你也可以试试这个

Math.round(x * 100) / 100

document.getElementById(“epr_fctot”).innerHTML=x.toFixed(2)不起作用?在我删除了所有parseFloat之后,它起作用,因为我将值保存在float中。感谢您的帮助。document.getElementById(“epr_fctot”).innerHTML=x.toFixed(2)不起作用?在我删除所有parseFloat后,它起作用,因为我将值保存在float中。谢谢你的帮助。重写原型原子类型(如字符串、布尔等)不是一个好的做法。我已经编辑了一些。你可以检查一下。我向你道歉,我不应该那样做。我真的很抱歉。不用担心,它现在不见了。这样的事情不是一个好答案的一部分。此外,OP在发布答案时会收到通知,只是明天会看到一些新用户。谢谢你们的帮助。实际上我是stackoverflow的新手。重写原型原子类型(如字符串、布尔等)不是一个好的做法。我已经编辑了一些。你可以检查一下。我向你道歉,我不应该那样做。我真的很抱歉。不用担心,它现在不见了。这样的事情不是一个好答案的一部分。此外,OP在发布答案时会收到通知,只是明天会看到一些新用户。谢谢你们的帮助。实际上我是stackoverflow的新手。