Web Analytics Made Easy -
StatCounter convert "1" to 1? - CodingForum

Announcement

Collapse
No announcement yet.

convert "1" to 1?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • convert "1" to 1?

    hello,

    i was trying to make a calculator type thing that uses prompts...

    the problem is "5" + "5" = 55... is there any way to make a number that is not a real number to a real number? does that make sense? i tryed using eval() but it didnt work...

    thanks in advance...
    UNDER CONSTRUCTION

  • #2
    Hello -

    You'll want to use parseFloat() or parseInt() around the number that is a string.

    From W3schools:

    parseInt(): The parseInt() function returns an integer defined by the string value.

    The parsing ends on the first character that is not a leading "-", "+", or a decimal digit.

    parseFloat(): The parseFloat() function returns a floating-point value defined by the string value.

    The parsing ends on the first character that can not be parsed as a floating-point value.



    ie.
    Code:
    <script language="javascript">
    var a="5";
    var b=5;
    
    var c=parseFloat(a)+b;
    </script>
    Hope That Helps
    Basscyst
    Last edited by Basscyst; Feb 23, 2004, 07:51 PM.
    Helping to build a bigger box. - Adam Matthews

    Comment


    • #3
      omg...

      it helped better then i expected! thankyou! thankyou!

      very much appreciated.
      UNDER CONSTRUCTION

      Comment

      Working...
      X