的String.Format相同的code不同的视图 [英] String.Format Same Code Different View

查看:171
本文介绍了的String.Format相同的code不同的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个code这样的;

I have a code like this;

GridView1.FooterRow.Cells[11].Text = String.Format("{0:c}", sumKV)

在我的电脑这个code给出这样的结果;

In my computer this code gives a result like that;

但是,当我上传此code到我的虚拟机,它看起来像这样;

But when I upload this code to my virtual machine it looks like this;

TL 表示土耳其里拉。但我不希望显示的货币。我只是想号码。

TL means Turkish Liras. But I don't want to show the currency. I just want numbers.

我也不想换号的格式化。 (像257.579,02)

I also don't want to change the formating of numbers. (Like 257.579,02)

我怎么只能删除 TL 在这个code?

How can I only delete TL in this code?

推荐答案

我会用这样的:

var cultureWithoutCurrencySymbol = 
    (CultureInfo)CultureInfo.CurrentCulture.Clone();
cultureWithoutCurrencySymbol.NumberFormat.CurrencySymbol = "";
GridView1.FooterRow.Cells[11].Text = 
            String.Format(cultureWithoutCurrencySymbol, "{0:c}", sumKV).Trim();

背景:结果
这仍将保持货币格式化当前的文化,它只是删除了货币符号。结果
您可以保存在某个地方这种特殊的文化,所以你不必每次需要格式化你的价值观时间创建它。

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.

更新:


  • 现在,它甚至编译...; - )

  • 新增了 TRIM(),因为那里仍是格式化号码后一个空格。

  • Now it even compiles... ;-)
  • Added a Trim(), because there is still a space after the formated number.

这篇关于的String.Format相同的code不同的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆