IsmailS
IsmailS

Reputation: 10863

Get only two decimal points in money datatype in SQL Server

SELECT ROUND(123.4567, 2)` gives me `123.4600`

But I need 123.46.

Data type of field is money.

Solution:

<%# DataBinder.Eval(Container.DataItem, "FieldName","{0:0.00}") %>

Upvotes: 10

Views: 66001

Answers (5)

Christopher Huff
Christopher Huff

Reputation: 61

@IsmailS - To me, the larger picture is to let the data server format as much as possible, especially when it's something as simple as an inline cast. It yields less clutter in your other code. For example, casting Price, a money field:

select CAST(Price as numeric(17,2)) Price from PriceTable

YMMV - It's my personal experience.

Upvotes: 4

Abhishek Singh
Abhishek Singh

Reputation: 101

SELECT FORMAT(123.4567,'N2')

It will Help You Out

Upvotes: 2

abatishchev
abatishchev

Reputation: 100278

If applicable, format on the view layer, not on the data layer, i.e. read all the data and truncate it later (such as in C# client)

Upvotes: 13

Anirudha
Anirudha

Reputation: 29

SELECT ROUND(123.4567, 2,1) 

See http://msdn.microsoft.com/en-us/library/ms175003(SQL.90).aspx

Upvotes: 2

Neil Knight
Neil Knight

Reputation: 48547

SELECT CAST(ROUND(123.4567, 2) AS MONEY)

Will do what you are after

Upvotes: 26

Related Questions