Solved

Decimal places only show two

Posted on 2014-11-11
4
111 Views
Last Modified: 2014-11-11
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
Comment
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
  • Learn & ask questions
  • 2
4 Comments
 
LVL 66

Accepted Solution

by:
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

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

Author Closing Comment

by:vbnetcoder
ID: 40435134
ty
0
 
LVL 66

Expert Comment

by:Jim Horn
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) 

Open in new window


Thanks for the grade.  Good luck with your project.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

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.

728 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