SQL rounding problem

Posted on 2011-04-29
Last Modified: 2012-08-13
Hello EE,

lets say I have this code:

DEClare @test decimal(10, 4)

set @test = 333.3334

How could I do a select that returns 2 decimals, but   like that:   333.34

because I have a 4 at the end... I would like to show 333.34  
the thing is that I saved inside table as money and it saves 4 decimals. I have a 4 at the fourth decimal.

any ideas.. ?
Question by:PhilippeRenaud
    LVL 32

    Expert Comment


    select Round(@test, 2)
    LVL 142

    Accepted Solution

    that would mean round up?

    please check out these expression to choose what you actually need:
    DEClare @test decimal(10, 4)
    set @test = 333.3334
    select @test, round(@test, 2), ceiling(@test), ceiling(@test * 100) / 100, floor( @test) , floor(@test * 100) / 100

    Open in new window

    LVL 1

    Author Closing Comment

    ahhh floor works....!

    thanks angel
    LVL 1

    Author Comment

    sorry I meant Ceiling  *100

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
    The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
    Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
    Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now