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. Decimals passing problem.

Decimals passing problem.

Scheduled Pinned Locked Moved ASP.NET
databasecsharpasp-nethelpquestion
6 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.
  • M Offline
    M Offline
    macca24
    wrote on last edited by
    #1

    Decimals problem. I have a stored procedure that returns values as decimals if I run it on query analyzer. The problem I have is that when the value is passed to my asp.net application the decimal places disappear and the values are rounded to the nearest whole number. Here is my stored procedure: CREATE PROCEDURE sproc_GetTown ( @Town varchar(100), @TdPermUnits As int OUTPUT, @TdHHUnits As int OUTPUT, @TdHH Decimal(9,2) OUTPUT, @TdPerm Decimal(9,2) OUTPUT, @TdTotal int OUTPUT ) AS SELECT @TdPermUnits = TP_TOTAL, @TdHHUnits = THH_TOTAL FROM TOWN WHERE Town = @Town SELECT @TdTotal = @TdPermUnits + @TdHHUnits SELECT @TdPerm = 100.00 * @TdPermUnits / @TdTotal SELECT @TdHH = 100.00 * @TdHHUnits / @TdTotal GO Here is my asp.net application: oCmd = New SqlCommand("sproc_GetTown", oConn) oCmd.CommandType = Data.CommandType.StoredProcedure oParam = oCmd.Parameters.Add("@Town", Data.SqlDbType.VarChar, 100) oParam.Direction = Data.ParameterDirection.Input oParam.Value = Townland oParam = oCmd.Parameters.Add("@TdHH", Data.SqlDbType.Decimal, 9, 2) oParam.Direction = Data.ParameterDirection.Output oParam = oCmd.Parameters.Add("@TdPerm", Data.SqlDbType.Decimal, 9, 2) oParam.Direction = Data.ParameterDirection.Output oParam = oCmd.Parameters.Add("@TdHHUnits", Data.SqlDbType.Int, 4) oParam.Direction = Data.ParameterDirection.Output oParam = oCmd.Parameters.Add("@TdPermUnits", Data.SqlDbType.Int, 4) oParam.Direction = Data.ParameterDirection.Output oParam = oCmd.Parameters.Add("@TdTotal", Data.SqlDbType.Int, 4) oParam.Direction = Data.ParameterDirection.Output oConn.Open() oCmd.ExecuteNonQuery() oConn.Close() Dim ldcTDHH As Decimal ldcTDHH = oCmd.Parameters("@TdHH").Value The value in ldcTDHH is always rounded off to the nearest whole number. Anyone know whats wrong? macca

    E G A 3 Replies Last reply
    0
    • M macca24

      Decimals problem. I have a stored procedure that returns values as decimals if I run it on query analyzer. The problem I have is that when the value is passed to my asp.net application the decimal places disappear and the values are rounded to the nearest whole number. Here is my stored procedure: CREATE PROCEDURE sproc_GetTown ( @Town varchar(100), @TdPermUnits As int OUTPUT, @TdHHUnits As int OUTPUT, @TdHH Decimal(9,2) OUTPUT, @TdPerm Decimal(9,2) OUTPUT, @TdTotal int OUTPUT ) AS SELECT @TdPermUnits = TP_TOTAL, @TdHHUnits = THH_TOTAL FROM TOWN WHERE Town = @Town SELECT @TdTotal = @TdPermUnits + @TdHHUnits SELECT @TdPerm = 100.00 * @TdPermUnits / @TdTotal SELECT @TdHH = 100.00 * @TdHHUnits / @TdTotal GO Here is my asp.net application: oCmd = New SqlCommand("sproc_GetTown", oConn) oCmd.CommandType = Data.CommandType.StoredProcedure oParam = oCmd.Parameters.Add("@Town", Data.SqlDbType.VarChar, 100) oParam.Direction = Data.ParameterDirection.Input oParam.Value = Townland oParam = oCmd.Parameters.Add("@TdHH", Data.SqlDbType.Decimal, 9, 2) oParam.Direction = Data.ParameterDirection.Output oParam = oCmd.Parameters.Add("@TdPerm", Data.SqlDbType.Decimal, 9, 2) oParam.Direction = Data.ParameterDirection.Output oParam = oCmd.Parameters.Add("@TdHHUnits", Data.SqlDbType.Int, 4) oParam.Direction = Data.ParameterDirection.Output oParam = oCmd.Parameters.Add("@TdPermUnits", Data.SqlDbType.Int, 4) oParam.Direction = Data.ParameterDirection.Output oParam = oCmd.Parameters.Add("@TdTotal", Data.SqlDbType.Int, 4) oParam.Direction = Data.ParameterDirection.Output oConn.Open() oCmd.ExecuteNonQuery() oConn.Close() Dim ldcTDHH As Decimal ldcTDHH = oCmd.Parameters("@TdHH").Value The value in ldcTDHH is always rounded off to the nearest whole number. Anyone know whats wrong? macca

      E Offline
      E Offline
      eyeseetee
      wrote on last edited by
      #2

      apply the value to a string in the code behind then convert to a decimal in code behind, this might help

      M 1 Reply Last reply
      0
      • E eyeseetee

        apply the value to a string in the code behind then convert to a decimal in code behind, this might help

        M Offline
        M Offline
        macca24
        wrote on last edited by
        #3

        Excuse me, I clicked the unhelpful button but it somehow marked this as the Answer !!!

        E 1 Reply Last reply
        0
        • M macca24

          Excuse me, I clicked the unhelpful button but it somehow marked this as the Answer !!!

          E Offline
          E Offline
          eyeseetee
          wrote on last edited by
          #4

          try decimal.Round() method. and then round to two decimal places

          1 Reply Last reply
          0
          • M macca24

            Decimals problem. I have a stored procedure that returns values as decimals if I run it on query analyzer. The problem I have is that when the value is passed to my asp.net application the decimal places disappear and the values are rounded to the nearest whole number. Here is my stored procedure: CREATE PROCEDURE sproc_GetTown ( @Town varchar(100), @TdPermUnits As int OUTPUT, @TdHHUnits As int OUTPUT, @TdHH Decimal(9,2) OUTPUT, @TdPerm Decimal(9,2) OUTPUT, @TdTotal int OUTPUT ) AS SELECT @TdPermUnits = TP_TOTAL, @TdHHUnits = THH_TOTAL FROM TOWN WHERE Town = @Town SELECT @TdTotal = @TdPermUnits + @TdHHUnits SELECT @TdPerm = 100.00 * @TdPermUnits / @TdTotal SELECT @TdHH = 100.00 * @TdHHUnits / @TdTotal GO Here is my asp.net application: oCmd = New SqlCommand("sproc_GetTown", oConn) oCmd.CommandType = Data.CommandType.StoredProcedure oParam = oCmd.Parameters.Add("@Town", Data.SqlDbType.VarChar, 100) oParam.Direction = Data.ParameterDirection.Input oParam.Value = Townland oParam = oCmd.Parameters.Add("@TdHH", Data.SqlDbType.Decimal, 9, 2) oParam.Direction = Data.ParameterDirection.Output oParam = oCmd.Parameters.Add("@TdPerm", Data.SqlDbType.Decimal, 9, 2) oParam.Direction = Data.ParameterDirection.Output oParam = oCmd.Parameters.Add("@TdHHUnits", Data.SqlDbType.Int, 4) oParam.Direction = Data.ParameterDirection.Output oParam = oCmd.Parameters.Add("@TdPermUnits", Data.SqlDbType.Int, 4) oParam.Direction = Data.ParameterDirection.Output oParam = oCmd.Parameters.Add("@TdTotal", Data.SqlDbType.Int, 4) oParam.Direction = Data.ParameterDirection.Output oConn.Open() oCmd.ExecuteNonQuery() oConn.Close() Dim ldcTDHH As Decimal ldcTDHH = oCmd.Parameters("@TdHH").Value The value in ldcTDHH is always rounded off to the nearest whole number. Anyone know whats wrong? macca

            G Offline
            G Offline
            Guffa
            wrote on last edited by
            #5

            Are you certain that the value in the ldcTDHH variable is rounded off? How do you determine what the variable actually contains?

            Despite everything, the person most likely to be fooling you next is yourself.

            1 Reply Last reply
            0
            • M macca24

              Decimals problem. I have a stored procedure that returns values as decimals if I run it on query analyzer. The problem I have is that when the value is passed to my asp.net application the decimal places disappear and the values are rounded to the nearest whole number. Here is my stored procedure: CREATE PROCEDURE sproc_GetTown ( @Town varchar(100), @TdPermUnits As int OUTPUT, @TdHHUnits As int OUTPUT, @TdHH Decimal(9,2) OUTPUT, @TdPerm Decimal(9,2) OUTPUT, @TdTotal int OUTPUT ) AS SELECT @TdPermUnits = TP_TOTAL, @TdHHUnits = THH_TOTAL FROM TOWN WHERE Town = @Town SELECT @TdTotal = @TdPermUnits + @TdHHUnits SELECT @TdPerm = 100.00 * @TdPermUnits / @TdTotal SELECT @TdHH = 100.00 * @TdHHUnits / @TdTotal GO Here is my asp.net application: oCmd = New SqlCommand("sproc_GetTown", oConn) oCmd.CommandType = Data.CommandType.StoredProcedure oParam = oCmd.Parameters.Add("@Town", Data.SqlDbType.VarChar, 100) oParam.Direction = Data.ParameterDirection.Input oParam.Value = Townland oParam = oCmd.Parameters.Add("@TdHH", Data.SqlDbType.Decimal, 9, 2) oParam.Direction = Data.ParameterDirection.Output oParam = oCmd.Parameters.Add("@TdPerm", Data.SqlDbType.Decimal, 9, 2) oParam.Direction = Data.ParameterDirection.Output oParam = oCmd.Parameters.Add("@TdHHUnits", Data.SqlDbType.Int, 4) oParam.Direction = Data.ParameterDirection.Output oParam = oCmd.Parameters.Add("@TdPermUnits", Data.SqlDbType.Int, 4) oParam.Direction = Data.ParameterDirection.Output oParam = oCmd.Parameters.Add("@TdTotal", Data.SqlDbType.Int, 4) oParam.Direction = Data.ParameterDirection.Output oConn.Open() oCmd.ExecuteNonQuery() oConn.Close() Dim ldcTDHH As Decimal ldcTDHH = oCmd.Parameters("@TdHH").Value The value in ldcTDHH is always rounded off to the nearest whole number. Anyone know whats wrong? macca

              A Offline
              A Offline
              Adeel Chaudhry
              wrote on last edited by
              #6

              Try by splitting the decimal value in 2 strings and passing with concatenation, don't forget to add "." in between. If DBMS is SQL Server 2005, it will work...the problem is due to different ways .NET and SQL Server 2005 stores the decimal value. HTH

              Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.

              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