Connect with Expertise | Find Experts, Get Answers, Share Insights

parse a number to float problem

 
Join Date: Jan 2010
Posts: 5
#1: Jan 31 '10
hello,

i know php but i have got no knowledge on ajax. this is the function my programmer made long time ago. it is showing the total value on the text areas. The problem am facing now is:

forexample if the value on the field is: 1.50 it turns into 1.

What can i do to solve the problem. i think it is something to do with parseInt

Expand|Select|Wrap|Line Numbers
  1.  
  2. function amtTot(){
  3.  
  4.     //fee_tot1
  5.     //alert(document.getElementById("fee_tot1").value);
  6.     var tot_amt=parseInt(document.getElementById("fee_tot1").value)+parseInt(document.getElementById("fee_tot2").value)+parseInt(document.getElementById("fee_tot3").value)+parseInt(document.getElementById("fee_tot4").value)+parseInt(document.getElementById("fee_tot7").value)+parseInt(document.getElementById("fee_tot8").value);
  7.     //alert(tot_amt);
  8.     document.getElementById("tot_amt").value=tot_amt;
  9.     addValueText();
  10.     //tot_amt
  11. }    
  12.  
  13.  
thanks all.

✓ answered by Dormilich

i think it is something to do with parseInt
that’s right. parseInt() creates integer values. what you want are floats, thus parseFloat().

Dormilich's Avatar
E
M
C
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 5,372
#2: Jan 31 '10

re: parse a number to float problem


i think it is something to do with parseInt
that’s right. parseInt() creates integer values. what you want are floats, thus parseFloat().
 
Join Date: Jan 2010
Posts: 5
#3: Jan 31 '10

re: parse a number to float problem


thanks alot. it works perfect now
gits's Avatar
E
M
C
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,694
#4: Jan 31 '10

re: parse a number to float problem


thread title changed - since that has nothing to do with AJAX ... and to help other users to find the issue better it is applicable to have a better desciption that might be found by a seach ... please remember to use a good thread title

kind regards,
MOD
Reply