Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Convert String to Int

Convert String to Int

Scheduled Pinned Locked Moved ASP.NET
question
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    siva455
    wrote on last edited by
    #1

    Hi, Please let me know how can i convert string x="10000000000" to int... i tried Convert.Int64 but im getting exception that number is too long or too short to store value in INt32..

    L 1 Reply Last reply
    0
    • S siva455

      Hi, Please let me know how can i convert string x="10000000000" to int... i tried Convert.Int64 but im getting exception that number is too long or too short to store value in INt32..

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I think the number is exceeding the limit of Int32 or Int64 try following code for successfully converting your string to number

      If number >= Int32.MinValue And number <= Int32.MaxValue Then
      newNumber = Convert.ToInt32(number)
      Console.WriteLine("Successfully converted {0} to an Int32.", _
      newNumber)
      Else
      Console.WriteLine("Unable to convert {0} to an Int32.", number)
      End If

      You can use the same logic for Int64. HTH

      Jinal Desai - LIVE Experience is mother of sage....

      S 1 Reply Last reply
      0
      • L Lost User

        I think the number is exceeding the limit of Int32 or Int64 try following code for successfully converting your string to number

        If number >= Int32.MinValue And number <= Int32.MaxValue Then
        newNumber = Convert.ToInt32(number)
        Console.WriteLine("Successfully converted {0} to an Int32.", _
        newNumber)
        Else
        Console.WriteLine("Unable to convert {0} to an Int32.", number)
        End If

        You can use the same logic for Int64. HTH

        Jinal Desai - LIVE Experience is mother of sage....

        S Offline
        S Offline
        siva455
        wrote on last edited by
        #3

        i think maxvalue for Int64 is 9,223,372,036,854,775,808 which is greater than 10000000000

        L 1 Reply Last reply
        0
        • S siva455

          i think maxvalue for Int64 is 9,223,372,036,854,775,808 which is greater than 10000000000

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          pradeep455 wrote:

          i tried Convert.Int64 but im getting exception that number is too long or too short to store value in INt32..

          The error says number is too long or too short to store value in Int32.. So I think you are trying with Int32. HTH

          Jinal Desai - LIVE Experience is mother of sage....

          S 1 Reply Last reply
          0
          • L Lost User

            pradeep455 wrote:

            i tried Convert.Int64 but im getting exception that number is too long or too short to store value in INt32..

            The error says number is too long or too short to store value in Int32.. So I think you are trying with Int32. HTH

            Jinal Desai - LIVE Experience is mother of sage....

            S Offline
            S Offline
            siva455
            wrote on last edited by
            #5

            even i tried with Convert.Int64 also..same error.. and im stroing in Int64 variable..still im getting the error..

            F 1 Reply Last reply
            0
            • S siva455

              even i tried with Convert.Int64 also..same error.. and im stroing in Int64 variable..still im getting the error..

              F Offline
              F Offline
              FarmerHE
              wrote on last edited by
              #6

              Try using the int64 parser Int64.Parse(string input) Best Regards HE

              S 1 Reply Last reply
              0
              • F FarmerHE

                Try using the int64 parser Int64.Parse(string input) Best Regards HE

                S Offline
                S Offline
                siva455
                wrote on last edited by
                #7

                ya even that was not working...

                M 1 Reply Last reply
                0
                • S siva455

                  ya even that was not working...

                  M Offline
                  M Offline
                  michaelschmitt
                  wrote on last edited by
                  #8

                  "Was" not working or "is" not working? The above mentioned solution (int64 + parse) works fine. Tested:

                  string test = "10000000000";

                  System.Int64 int64 = Int64.Parse(test);

                  and it is totally ok.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups