字符串格式 [英] string formatting
本文介绍了字符串格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用.net Windows窗体应用程序.
我使用convert :: tostring将双精度值转换为字符串.
如何将其转换为2个小数点数字?
如果我的double值是23,我希望它显示为23.00.
using .net windows form application.
I use convert::tostring to convert a double value to string.
How do I convert it to a 2 decimal point number?
If my double value is 23, I want it to show as 23.00.
How to do that??
推荐答案
您可以为此目的直接使用Double.ToString
方法(请参阅 [
You may use directly theDouble.ToString
method for the purpose (see "Custom Numeric Format Strings" at MSDN[^]):
double d = 23;
string s = d.ToString("0.00", CultureInfo.InvariantCulture);
:)
这篇关于字符串格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文