CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2001
    Posts
    24

    Question Converting string to number

    Hello All,

    I am facing problem in converting string to number.

    I have two strings...

    strFrom = "123456789123456789123";
    strTo = "123456789123456789130";

    I converted them into integers......by using parseInt and Math.abs

    But output of parseInt("123456789123456789123") is not proper integer output. Same is happening with Math.abs.

    The difference of these two strings is supposed to be 7............. after converting into integers

    but i am not able to get that................

    can anyone help me...............

    Thanks in advance..

    Shraddha Biyani

  2. #2
    Join Date
    Jun 2002
    Location
    Sweden
    Posts
    136
    Well. This 'integer' is far too large to be contained in any programming language's interger datacarrier. I assume you're using Java, from the functions you mentioned. Try using a double, instead, but I think even that's too small. Why the huge number?
    Captain Obvious

    Documentation is your friend

  3. #3
    Join Date
    Jul 2002
    Location
    Don't Know, Don't Care
    Posts
    346
    it's not java, it's javascript, very different.

    there is no double type in javascript....there is no integer type, the browser does the deciding, you just declare
    var someVariable;

    try this
    Code:
    <html>
    <body>
    <script language="javascript">
    //can only handle a 16 digit number...i suggest breaking apart somehow then working with peices of it.
    var first="9999999999999999";
    var second="9999999999999998";
    var third=first-second;
    //or var third=parseInt(first)-parseInt(second); both have same result
    
    alert(third);
    </script>
    </body>
    </html>
    i tested it and it works fine

    C G C F A D--Feel the Noise

    "When your life goes nowhere and leads back to me, doesn't that tell you something?"
    ~Gray Area Fury

  4. #4
    Join Date
    Jun 2002
    Location
    Sweden
    Posts
    136
    Disregarding it being javascript, and there not being any datatypes in said language, the number was still too big. ;p
    Captain Obvious

    Documentation is your friend

  5. #5
    Join Date
    Jul 2002
    Location
    Don't Know, Don't Care
    Posts
    346
    yes, that's why i noted it in my sample code.
    beyond that, he was doing it wrong anyway, a string and an integer are interchangeable in javascript (as long as they are numeric characters)

    C G C F A D--Feel the Noise

    "When your life goes nowhere and leads back to me, doesn't that tell you something?"
    ~Gray Area Fury

  6. #6
    Join Date
    Jun 2002
    Location
    Sweden
    Posts
    136
    Really? Useful.
    Captain Obvious

    Documentation is your friend

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured