开发者

Get only two decimal points in money datatype in SQL Server

开发者 https://www.devze.com 2023-01-12 05:19 出处:网络
SELECT ROUND(123.4567, 2)` gives me `123.4600` But I need 123.46. Data type of field is money. Solution:
SELECT ROUND(123.4567, 2)` gives me `123.4600`

But I need 123.46.

Data type of field is money.

Solution:

<%# DataB开发者_如何学编程inder.Eval(Container.DataItem, "FieldName","{0:0.00}") %>


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

Will do what you are after


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)


@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.


SELECT FORMAT(123.4567,'N2')

It will Help You Out


SELECT ROUND(123.4567, 2,1) 

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

0

精彩评论

暂无评论...
验证码 换一张
取 消