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. Database & SysAdmin
  3. Database
  4. Problem with Decimal Places and Rounding off

Problem with Decimal Places and Rounding off

Scheduled Pinned Locked Moved Database
csharpasp-netdatabasecom
3 Posts 2 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.
  • V Offline
    V Offline
    Vimalsoft Pty Ltd
    wrote on last edited by
    #1

    Good Day All i have a Following Query 1) Query 1

    DECLARE @FINALVAUE VARCHAR(MAX) = (Convert(decimal,@CAUSATIVE_FACTORS_ID) - 1) + Convert(decimal,@LU_PERCENTAGE_FAILURE_IN_SAMPLE_ID) + Convert(decimal,@LU_REPORTING_HISTORY_ID)
    PRINT @FINALVAUE -- the answer is 3

    The Calculation is like this 2) Query 2

    DECLARE @FINAL VARCHAR(MAX)
    SET @FINAL= (4-1) + 0.08 + 0.2
    SELECT @FINAL -- the asnwer is 3.28

    The first Query i am retrieving values from the Variables which are varchar and converting to decimal and doing the calculations. and the second Query i am just taking the value as is. i used this to debug in trying to solve this problem. My problem here in the first Query in the @FINALVAUE variable the answer is "3" and in the second Query the answer is "3.28" , i want the first Query to display the same value which is "3.28" Thanks

    Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.com vuyiswa[at]dotnetfunda.com http://www.Dotnetfunda.com

    Kornfeld Eliyahu PeterK 1 Reply Last reply
    0
    • V Vimalsoft Pty Ltd

      Good Day All i have a Following Query 1) Query 1

      DECLARE @FINALVAUE VARCHAR(MAX) = (Convert(decimal,@CAUSATIVE_FACTORS_ID) - 1) + Convert(decimal,@LU_PERCENTAGE_FAILURE_IN_SAMPLE_ID) + Convert(decimal,@LU_REPORTING_HISTORY_ID)
      PRINT @FINALVAUE -- the answer is 3

      The Calculation is like this 2) Query 2

      DECLARE @FINAL VARCHAR(MAX)
      SET @FINAL= (4-1) + 0.08 + 0.2
      SELECT @FINAL -- the asnwer is 3.28

      The first Query i am retrieving values from the Variables which are varchar and converting to decimal and doing the calculations. and the second Query i am just taking the value as is. i used this to debug in trying to solve this problem. My problem here in the first Query in the @FINALVAUE variable the answer is "3" and in the second Query the answer is "3.28" , i want the first Query to display the same value which is "3.28" Thanks

      Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.com vuyiswa[at]dotnetfunda.com http://www.Dotnetfunda.com

      Kornfeld Eliyahu PeterK Offline
      Kornfeld Eliyahu PeterK Offline
      Kornfeld Eliyahu Peter
      wrote on last edited by
      #2

      CONVERT(DECIMAL, value) will convert without decimal palces :) ... Use something like CONVERT(DECIMAL(4, 2), value)... http://msdn.microsoft.com/en-us/library/ms187746.aspx[^]

      I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

      "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

      V 1 Reply Last reply
      0
      • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

        CONVERT(DECIMAL, value) will convert without decimal palces :) ... Use something like CONVERT(DECIMAL(4, 2), value)... http://msdn.microsoft.com/en-us/library/ms187746.aspx[^]

        I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

        V Offline
        V Offline
        Vimalsoft Pty Ltd
        wrote on last edited by
        #3

        Thanks that saved the day.

        Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.com vuyiswa[at]dotnetfunda.com http://www.Dotnetfunda.com

        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