[Javascript] String -> Number impossible

Marcelo Wolfgang grillo at gmail.com
Tue Aug 22 05:46:42 CDT 2006


Hi Peter,

Well I'm sure they are string because a couple of things:

1) if I do someVar = isNaN(rdVal ) // someVar = true
else if I do someVar = isNaN(total) // someVar = false before trying
to add rdVal

2) the total is showed as 15070,60 // where 150 is the price and rdVal
is 70,60 ( total is combining it instead of summing it.

Still I can't figure out why this is happening, I'm frustated by this

TIA
Marcelo

On 8/22/06, Peter Brunone <peter at brunone.com> wrote:
>  What leads you to believe that it is a string, even after parseFloat?
>
>
> > total = total+(array_prices[i])*(2);// this value works here, but I
> > hardcoded it
>
>    I'm curious about this... you're assigning the array elements as strings
> (i.e. with quotes) rather than as integers.
>
> Peter
>
>  From: "Marcelo Wolfgang" grillo at gmail.com
>
> Hi list,
>
> First forgive me for posting code up in the email, there's no online
> page that I can show the script.
> I'm having a terrible, like 2 hours wasted on this terrible error,
> trying to figure this out:
> Here's the code:
>
>
>
> array_prices = new Array();
> array_prices[1] = '115'; //these values are coming from a db
> array_prices[2] = '95';
>
> function getCheckedValue(radioObj) {
>  var radioLength = radioObj.length;
>  for(var i = 0; i < radioLength; i++) {
>  if(radioObj[i].checked) {
>  return radioObj[i].value;
>  }
>  }
> }
>
> function updateTotal(){
>  total = 0;
>  totalField = document.getElementById('valorOnlyNumber');
>  for (i=1; i < array_prices.length; i++){
>  total = total+(array_prices[i])*(2);// this value works here, but I
> hardcoded it
>  }
>  rdVal =
> getCheckedValue(document.frm_calcShipping.valFrete);
>  if (rdVal != 0){
>  total = total+rdVal;
>  }
>  totalField.innerHTML = total;
> }
>
>
>
> and these are my radios:
>
>
>
> name="valFrete" />R$ 6,70
>
>
>
> name="valFrete" />R$ 7,20
>
>
>
> name="valFrete" />R$ 12,60
>
>
>
> name="valFrete" />R$ 18,60
>
>
> R$ 210.00
>
>
> +++++++++++++++++++++
> The problem is that rdVal is always a string, I've tried
>
> rdVal =
> parseFloat('getCheckedValue(document.frm_calcShipping.valFrete)')
>
> still a string
>
> I can't figure out what to do please someone advice
>
> TIA
> Marcelo
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>
>
>



More information about the Javascript mailing list