Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: parseInt(abc)

  1. #1
    New Coder
    Join Date
    Oct 2004
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    parseInt(abc)

    i have problem with this

    function Total()
    {
    abc = "1,236.00"
    cde = "1,000.00"

    final = parseInt(abc) + parseInt(cde);

    }

    the result i get is "2", statement wrong??
    Pls help..10s

  • #2
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You posted in the wrong forum.. and.. no comma is necessary.. and you should probably be using numbers instead of strings but I didn't change that..
    Code:
    function Total()
    {
        var abc = "1236.00";
        var cde = "1000.00";
        var final = parseInt(abc) + parseInt(cde);
    }
    ...

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    afaik, parseInt starts parsing the string from the left, the first position should be numeric. Whenever it finds a non-numeric character (fe your comma), it stops parsing. The numeric part, is converted to int var-type.
    So parseInt("1236.00"); should give int: 1
    and parseInt("1000.00"); should give int: 1
    together that makes int: 2
    I am the luckiest man in the world

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    So parseInt("1236.00"); should give int: 1
    and parseInt("1000.00"); should give int: 1
    Wrong.
    parseInt("1236.00"); should give int 1236
    and parseInt("1000.00"); should give int: 1000

    Anyway, javascript does not accept number in format

    ddd,ddd
    so get rid of that comma
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts


    oops, i meant to copy the values with the comma in it so it was meant this way:
    So parseInt("1,236.00"); should give int: 1
    and parseInt("1,000.00"); should give int: 1

    <note to="self">better watch out before you press submit reply</note>
    I am the luckiest man in the world


  •  

    Posting Permissions

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