本文介紹了將十進制轉換為 Varchar的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我在定義為十進制(8,3)的表中有一個十進制列.我想將此列包含在 Select
語句中,將其轉換為 Varchar
并且只顯示兩位小數.我似乎無法找到正確的選項組合來執行此操作,因為我嘗試的所有操作仍然會產生三位小數.
I have a decimal column in a table defined as decimal(8,3). I would like to include this column in a Select
statement, convert it to a Varchar
and only display two decimal places. I can't seem to find the right combination of options to do this because everything I try still produces three decimal places.
推薦答案
這是一種方法:
create table #work
(
something decimal(8,3) not null
)
insert #work values ( 0 )
insert #work values ( 12345.6789 )
insert #work values ( 3.1415926 )
insert #work values ( 45 )
insert #work values ( 9876.123456 )
insert #work values ( -12.5678 )
select convert(varchar,convert(decimal(8,2),something))
from #work
如果你想讓它右對齊,你應該這樣做:
if you want it right-aligned, something like this should do you:
select str(something,8,2) from #work
這篇關于將十進制轉換為 Varchar的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!