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. General Programming
  3. C#
  4. how to convert string to decimal

how to convert string to decimal

Scheduled Pinned Locked Moved C#
databasetutorial
7 Posts 6 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
    Sunil Wise
    wrote on last edited by
    #1

    hi frns below is the code snippet i used in my proj actually i'll be giving some decimal value in the textbox input. I want to insert that textbox value into my database table. In the database i used that particular column as datatype decimal with precision 5 and scale 2. SqlParameter pErrorPoints = new SqlParameter("@ErrorPoints", SqlDbType.Decimal); pErrorPoints.Value = decimal.Parse(txtPoints.Text.Trim()); if anybody knows the answer please do let me know regards sunilwise:)

    S N P S A 5 Replies Last reply
    0
    • S Sunil Wise

      hi frns below is the code snippet i used in my proj actually i'll be giving some decimal value in the textbox input. I want to insert that textbox value into my database table. In the database i used that particular column as datatype decimal with precision 5 and scale 2. SqlParameter pErrorPoints = new SqlParameter("@ErrorPoints", SqlDbType.Decimal); pErrorPoints.Value = decimal.Parse(txtPoints.Text.Trim()); if anybody knows the answer please do let me know regards sunilwise:)

      S Offline
      S Offline
      Sun Rays
      wrote on last edited by
      #2

      sunilwise wrote:

      pErrorPoints.Value = decimal.Parse(txtPoints.Text.Trim());

      Hi, these are two ways to do that. Convert.ToDecimal(txtPoints.Text.Trim()) or Decimal.Parse(txtPoints.Text.Trim())

      Thanks, Sun Rays Rate this post if you like answer. My Articles

      S 1 Reply Last reply
      0
      • S Sunil Wise

        hi frns below is the code snippet i used in my proj actually i'll be giving some decimal value in the textbox input. I want to insert that textbox value into my database table. In the database i used that particular column as datatype decimal with precision 5 and scale 2. SqlParameter pErrorPoints = new SqlParameter("@ErrorPoints", SqlDbType.Decimal); pErrorPoints.Value = decimal.Parse(txtPoints.Text.Trim()); if anybody knows the answer please do let me know regards sunilwise:)

        N Offline
        N Offline
        N a v a n e e t h
        wrote on last edited by
        #3

        sunilwise wrote:

        decimal.Parse(txtPoints.Text.Trim());

        What is your question ? I see you are doing a conversion here.

        All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

        1 Reply Last reply
        0
        • S Sunil Wise

          hi frns below is the code snippet i used in my proj actually i'll be giving some decimal value in the textbox input. I want to insert that textbox value into my database table. In the database i used that particular column as datatype decimal with precision 5 and scale 2. SqlParameter pErrorPoints = new SqlParameter("@ErrorPoints", SqlDbType.Decimal); pErrorPoints.Value = decimal.Parse(txtPoints.Text.Trim()); if anybody knows the answer please do let me know regards sunilwise:)

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          You don't actually need to convert the value to a decimal to use it in a SqlParameter.Value. The conversion is useful to prove that it is a decimal, but isn't actually needed by the system.

          Deja View - the feeling that you've seen this post before.

          My blog | My articles

          1 Reply Last reply
          0
          • S Sunil Wise

            hi frns below is the code snippet i used in my proj actually i'll be giving some decimal value in the textbox input. I want to insert that textbox value into my database table. In the database i used that particular column as datatype decimal with precision 5 and scale 2. SqlParameter pErrorPoints = new SqlParameter("@ErrorPoints", SqlDbType.Decimal); pErrorPoints.Value = decimal.Parse(txtPoints.Text.Trim()); if anybody knows the answer please do let me know regards sunilwise:)

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

            be sure that you wrote only numbers in the TextBox. or set it in the try catch to see what is the problem ;)

            spaps

            1 Reply Last reply
            0
            • S Sunil Wise

              hi frns below is the code snippet i used in my proj actually i'll be giving some decimal value in the textbox input. I want to insert that textbox value into my database table. In the database i used that particular column as datatype decimal with precision 5 and scale 2. SqlParameter pErrorPoints = new SqlParameter("@ErrorPoints", SqlDbType.Decimal); pErrorPoints.Value = decimal.Parse(txtPoints.Text.Trim()); if anybody knows the answer please do let me know regards sunilwise:)

              A Offline
              A Offline
              Andrei Ungureanu
              wrote on last edited by
              #6

              I don't see your problem, but you can use Decimal.TryParse() to be sure that you have a decimal value in your textbox and avoid errors in your application. Hope it helps.

              I will use Google before asking dumb questions

              1 Reply Last reply
              0
              • S Sun Rays

                sunilwise wrote:

                pErrorPoints.Value = decimal.Parse(txtPoints.Text.Trim());

                Hi, these are two ways to do that. Convert.ToDecimal(txtPoints.Text.Trim()) or Decimal.Parse(txtPoints.Text.Trim())

                Thanks, Sun Rays Rate this post if you like answer. My Articles

                S Offline
                S Offline
                Sunil Wise
                wrote on last edited by
                #7

                Sun Rays wrote:

                Convert.ToDecimal(txtPoints.Text.Trim()) or Decimal.Parse(txtPoints.Text.Trim())

                ok i got it both are working my thanx to all those have answered my question from the bottom of my heart

                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