本文介紹了將十進(jìn)制轉(zhuǎn)換為 Varchar的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我在定義為十進(jìn)制(8,3)的表中有一個(gè)十進(jìn)制列.我想將此列包含在 Select
語(yǔ)句中,將其轉(zhuǎn)換為 Varchar
并且只顯示兩位小數(shù).我似乎無法找到正確的選項(xiàng)組合來執(zhí)行此操作,因?yàn)槲覈L試的所有操作仍然會(huì)產(chǎn)生三位小數(shù).
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
如果你想讓它右對(duì)齊,你應(yīng)該這樣做:
if you want it right-aligned, something like this should do you:
select str(something,8,2) from #work
這篇關(guān)于將十進(jìn)制轉(zhuǎn)換為 Varchar的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!