c# 格式化

來源:互聯網
上載者:User

標籤:部分   mat   format   小數點   內容   格式   回顧   style   補充   

  本部分是對c#基礎內容的回顧。

1:0預留位置和#預留位置 

  c#對數字格式化中常見的那些比如說貨幣格式那些通常比較常用的就不介紹了,本次我們就對比0預留位置和#預留位置差別和用途。

  0預留位置:如果位元整數部分如果不夠位元的話會補充0,小數的話如果多了位元會四捨五入。

       #站位符:整數部分如果有多個#預留位置但是我們格式化的整數位不夠的話是不會補充的,小數點後面的話 如果如果你取的最後一位剛好是0的話#預留位置不會顯示出來,否則就是和0站位符一樣輸出,如果四捨五入剛好進1的話那最後一位原始是0的話進1最後一位就是1了,回將位元列印出來。

1 float num1 = 1.004654f;       2 string strFormat = "{0:##.##}";3 string strFormat0 = "{0:00.00}";4 string.Format(strFormat, num1);//結果:15 string.Format(strFormat0,num1);//結果:01.00
float num1 = 1.009f;       string strFormat = "{0:##.##}";string strFormat0 = "{0:00.00}";string.Format(strFormat, num1);//結果:1.01string.Format(strFormat0,num1);//結果:01.01

 

 

c# 格式化

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.