lundi 28 août 2017

convert value int decimal

Hi I really need your help.

currently i used this code to do auto calculate.

But then I got 8.749999999999998 as an answer.(prefer to be 8.75) I tried to use fixed to two and still got the same answer.

<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>




Aucun commentaire:

Enregistrer un commentaire