Solved

t-sql money data type decimal places

Posted on 2016-11-08
4
245 Views
Last Modified: 2016-11-16
I'm using sql server 2008

I have a money column in sql server.
The data in the column has 4 decimal places.

In my select query how to i display only 2 decimal places?
0
Comment
Question by:maqskywalker
[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 52

Expert Comment

by:_agx_
ID: 41879387
Round() or Cast as type decimal, with two decimal places

DECLARE @money money
SET @money = 19.7562            
DECLARE @money money
SET @money = 19.7562            
SELECT  CAST(@money AS DECIMAL(18,2))
		, ROUND(@money, 2)

Open in new window

0
 
LVL 29

Assisted Solution

by:Pawan Kumar
Pawan Kumar earned 250 total points
ID: 41879801
Try below.. Here you can use Format Function or you can cast to Numeric, in this you can specify how many decimal places you want. I think format is good. <<Format function works only 2012+>>

DECLARE @money MONEY
SET @money = 43875435.324324234

SELECT CAST(@money AS NUMERIC(30,2)) 'UsingCast' , FORMAT(@money, '0.00') 'UsingFormat'

O/p
UsingCast                UsingFormat
43875435.32                43875435.32

You can also use ROUND and Floor functions like below-

SELECT CAST(ROUND(43875435.32932429,2,1) AS DECIMAL (19,2))
SELECT CAST(FLOOR(43875435.32932429*100)/100 AS DECIMAL (19,2))

Hope it helps !!
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 250 total points
ID: 41879833
SELECT CAST(@money AS NUMERIC(30,2))

That's the same as casting to DECIMAL. Type numeric and decimal are functionally equivalent.


FORMAT(@money, '0.00')

If you need a number, do not use Format. It returns a string, not a number.

>> syntax 1:  ROUND(number,2)  
>> syntax 2:  ROUND(number,2,1)

@maqskywalker - Be aware there's a subtle difference in behavior with ROUND(number, length, [function]).  Syntax 1 rounds the value, so 125.755 would become 125.76.  Syntax 2 truncates it, so 125.755 becomes 125.75
1
 
LVL 1

Author Closing Comment

by:maqskywalker
ID: 41889712
thanks.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

636 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