String.Format 相同代码不同视图
我有这样的代码;
GridView1.FooterRow.Cells[11].Text = String.Format("{0:c}", sumKV)
在我的计算机中,这段代码给出了这样的结果;
但是当我将此代码上传到我的虚拟机时,它看起来像这样;
TL 表示土耳其里拉。但我不想显示货币。我只想要数字。
我也不想改变数字的格式。 (如257.579,02)
如何才能只删除这段代码中的TL?
I have a code like this;
GridView1.FooterRow.Cells[11].Text = String.Format("{0:c}", sumKV)
In my computer this code gives a result like that;
But when I upload this code to my virtual machine it looks like this;
TL means Turkish Liras. But I don't want to show the currency. I just want numbers.
I also don't want to change the formating of numbers. (Like 257.579,02)
How can I only delete TL in this code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我会用这个:
背景:
这仍将保留当前区域性的货币格式,只是删除货币符号。
您可以将这种特殊的文化保存在某个地方,这样您就不必每次需要格式化值时都创建它。
更新:
Trim()
,因为格式化的数字后面仍然有一个空格。I would use this:
Background:
This will still keep the currency formatting for the current culture, it just removes the currency symbol.
You can save this special culture somewhere, so you don't have to create it every time you need to format your values.
UPDATE:
Trim()
, because there is still a space after the formated number.另一种选择是完全关闭当前线程的货币符号:
这样您将更改更少的代码。之后您可以随时将其更改回来:
Another option is to turn off the currency symbol entirely for the current thread:
That way you will change less code. You can always change it back afterwards:
由于您仅将 String.Format 与格式字符串一起使用,因此 sumKV 会根据应用程序中实际使用的 UI 区域性进行格式化。
要摆脱货币符号,请在
String.Format
中使用 InvariantCulture,如下所示:Because you are using String.Format with a format string only, sumKV is formatted according to the UI Culture actually used in your application.
To get rid with currency symbol, use InvariantCulture in
String.Format
this way :如果您不想显示货币,则不要使用货币格式代码 - {0:c}。
也许尝试类似以下内容:
查看这篇文章 - String.Format 双精度
If you don't want to show currency then don't use the currency formatting code - {0:c}.
Perhaps try something like the following:
See this article - String.Format doubles