.NET:十进制到圆形串 [英] .NET: Decimal to rounded string
本文介绍了.NET:十进制到圆形串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有一个十进制
,我怎么得到它的字符串版本保留两位小数?这是行不通的:
Math.Round(myDecimal,2)的ToString({0.00});
解决方案
不要使用大括号,他们是用一个较长的字符串中嵌入格式化值的String.Format
。使用这样的:
myDecimal.ToString(0.00);
If I have a decimal
, how do I get a string version of it with two decimal places? This isn't working:
Math.Round(myDecimal, 2).ToString("{0.00}");
解决方案
Don't use the curly brackets, they are for embedding a formatted value in a longer string using string.Format
. Use this:
myDecimal.ToString("0.00");
这篇关于.NET:十进制到圆形串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文