天天看點

Money類型轉化為String去除小數點後0解決方法

money類型轉化為string去除小數點後0

從資料庫提取money類型後,字元串如:1212.0000

如何使其成為1212      

      注:去掉了小數點

如果是:1212.0100

使其成為   1212.01

難道要循環截取   有沒有簡單的方法

我要在gridview中用到

------解決方案--------------------

double i = 1.1111;

string s = i.tostring( "0.00 ");

你的需求,不大符合實際,不管是什麼,monery都是保留2位才是

{0:0.00}

try

decimal d = 1212.0000m;

//decimal d =

1212.0100m;

response.write(d.tostring().trimend( ‘0 ‘).trimend( ‘. ‘));

1.

decimal d

= 1212.0100m;

d.tostring( "0.00 ");

// 支援的格式化字元串 0.00

2.

=========

sql server 中 money 帶4位小數點, smallmoney 帶2位小數點,精度自己查文檔

response.write( " <br /> ");

response.write(d.tostring( "0.#### "));

d = 1212.0100m;

response.write( "

<br /> ");

乘上10000 轉int再除以10000得到其他類型 比如付點或者雙精度 tostring就是了

tostring( "n0 ") or tostring( "f0 ")

但前面要為數字格式

gridview中用到有兩種

模版

<%# eval( "dtt ", "{0:n2} ")

%>

使其成為 1212.01

<%# eval( "dtt ", "{0:n0} ") %> 使其成為 字元串如:1212.0000

如何使其成為1212

資料類型轉成double。

我的問題是這樣解決的。