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. Remove decimal with out rounding.

Remove decimal with out rounding.

Scheduled Pinned Locked Moved Database
databasehelp
7 Posts 5 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.
  • K Offline
    K Offline
    kurangu
    wrote on last edited by
    #1

    Hi, I am using sql 2005.I have a value -0.026880000000000 but I want the result as -0.0268 just 3 decimals.If I use select convert(decimal(18,3),-0.026880000000000) I am getting -0.027 with rounded. can anybody help me out in this. Thx

    D T B P 4 Replies Last reply
    0
    • K kurangu

      Hi, I am using sql 2005.I have a value -0.026880000000000 but I want the result as -0.0268 just 3 decimals.If I use select convert(decimal(18,3),-0.026880000000000) I am getting -0.027 with rounded. can anybody help me out in this. Thx

      D Offline
      D Offline
      David Mujica
      wrote on last edited by
      #2

      Try this: a) Multiply the value by 1,000 b) Truncate the value c) Divide the number by 1,000 David

      K D 2 Replies Last reply
      0
      • D David Mujica

        Try this: a) Multiply the value by 1,000 b) Truncate the value c) Divide the number by 1,000 David

        K Offline
        K Offline
        kurangu
        wrote on last edited by
        #3

        HI, if i do like that select convert(decimal(18,3),(-0.0268000000000000000)*1000/1000) I am getting -0.027 which is again rounding.can you help me how to truncate the value with out rounding.

        1 Reply Last reply
        0
        • K kurangu

          Hi, I am using sql 2005.I have a value -0.026880000000000 but I want the result as -0.0268 just 3 decimals.If I use select convert(decimal(18,3),-0.026880000000000) I am getting -0.027 with rounded. can anybody help me out in this. Thx

          T Offline
          T Offline
          Tim Carmichael
          wrote on last edited by
          #4

          select convert(int,convert(decimal(18,5),-0.026880000000000)*100000.0)/100000.0

          1 Reply Last reply
          0
          • D David Mujica

            Try this: a) Multiply the value by 1,000 b) Truncate the value c) Divide the number by 1,000 David

            D Offline
            D Offline
            David Mujica
            wrote on last edited by
            #5

            I realize someone already replied, but here is my 2 cents ... select convert(decimal(18,3),(convert(integer,(-0.0268000000000000000)*1000)))/1000

            1 Reply Last reply
            0
            • K kurangu

              Hi, I am using sql 2005.I have a value -0.026880000000000 but I want the result as -0.0268 just 3 decimals.If I use select convert(decimal(18,3),-0.026880000000000) I am getting -0.027 with rounded. can anybody help me out in this. Thx

              B Offline
              B Offline
              Blue_Boy
              wrote on last edited by
              #6
              DECLARE @val AS VARCHAR(255)
              SET @val='-0.026880000000000'
              SELECT SUBSTRING(@val,1,CHARINDEX('.',@val)+4)
              

              I Love T-SQL "Don't torture yourself,let the life to do it for you."

              1 Reply Last reply
              0
              • K kurangu

                Hi, I am using sql 2005.I have a value -0.026880000000000 but I want the result as -0.0268 just 3 decimals.If I use select convert(decimal(18,3),-0.026880000000000) I am getting -0.027 with rounded. can anybody help me out in this. Thx

                P Offline
                P Offline
                PIEBALDconsult
                wrote on last edited by
                #7

                Use floor.

                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