码迷,mamicode.com
首页 > 其他好文 > 详细

Formatting is Specified but argument is not IFormattable

时间:2015-09-22 10:20:43      阅读:296      评论:0      收藏:0      [点我收藏+]

标签:

 

 

private void DeviceSetText(TextBox textBox, string text)
        {
            //处理text的显示值
            if (text != "0")  //小数位后保留2位
            {
                //小数点后保留2位小数
                text = string.Format("{0:0.00}", text);
            }
            textBox.Invoke((MethodInvoker) delegate
            {
                textBox.Text = text;
            });
        }
text = string.Format("{0:0.00}", text);

和下面的问题类似

 

http://stackoverflow.com/questions/2849688/formatting-is-specified-but-argument-is-not-iformattable

string listOfItemPrices = items.ToSemiColonList(item => string.Format("{0:C}", item.Price.ToString()));

By passing item.Price.ToString() to String.Format, you are passing a string, not a decimal.
Since strings cannot be used with format strings, you‘re getting an error.

You need to pass the Decimal value to String.Format by removing .ToString().

string.Format里面处理的是数字,但是传递了字符串,所以有这个提示

Formatting is Specified but argument is not IFormattable

标签:

原文地址:http://www.cnblogs.com/chucklu/p/4828075.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!