Avatar of Camillia
Camillia
Flag for United States of America asked on

Javascript concats instead of adding

I have this Javascript code. The addition line doesnt add. It concats. For example, i have 2 values: 100.00 and 10.00 . It comes out as 10.00100.00

I googled and "+" is the right thing to use. Not sure why it's not adding:

<script type="text/javascript">
     var amount = 0.00;
     function prices(price) {


         var tempAmount = document.getElementById('<%=x_amount.ClientID %>');
         alert(tempAmount.value);
         amount = price + tempAmount.value;
         alert(amount);

         tempAmount.value = amount;
        // alert(amount.value);
   


     }
  </script>

Open in new window

JavaScript

Avatar of undefined
Last Comment
rsly

8/22/2022 - Mon
rsly

Try

amount = price + parseFloat(tempAmount.value);

Open in new window


http://www.w3schools.com/jsref/jsref_parsefloat.asp
Camillia

ASKER
no, still comes out as this 10.00100
ASKER CERTIFIED SOLUTION
rsly

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes