Solved

# Decimal places only show two

Posted on 2014-11-11
111 Views
Select Number From Table

is returning

12.4653453544

i would like only the first two number after the decimal so it should be

12.46

HOW?
0
Question by:vbnetcoder
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2

LVL 66

Accepted Solution

Jim Horn earned 500 total points
ID: 40435074
Rounding or no rounding?

-- Rounding
Select CAST(Number as numeric(9,2)) From Table

-- No rounding (probably a better way to pull this off)
SELECT CAST(FLOOR(number * 100) / 100 as decimal(9,2)) From Table
0

LVL 13

Expert Comment

ID: 40435123
Jim, just curious, why do you cast the field rather than just using ROUND or FLOOR directly?
0

Author Closing Comment

ID: 40435134
ty
0

LVL 66

Expert Comment

ID: 40435142
>why do you cast the field rather than just using ROUND or FLOOR directly?
Round does the rounding, but doesn't change the data type, so rounding to two decimal places returns 12.4700000.  A fun nugget of info I learned the last time I sat for the 70-433 SQL 2008 Development exam.
``````Declare @number decimal(19,9) = 12.4653453544
Select CAST(@number as numeric(9,2))
SELECT ROUND(@number, 2)
``````

0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that witâ€¦
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
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.
###### Suggested Courses
Course of the Month7 days, 7 hours left to enroll