简体   繁体   English

Visual Studio中的非英语数字格式

[英]Non-English numeric formatting in Visual Studio

In English-US, the decimal separator symbol is "." 在英语-美国中,小数点分隔符是“。” So if I want to write the result of 100 + 25/100, it will be 100.25 (obviously). 因此,如果我想写100 + 25/100的结果,它将是100.25(显然)。

How will I write it in a constant in Visual Studio if I'm a french developer living in France? 如果我是居住在法国的法国开发人员,如何在Visual Studio中的常量中编写它? In France they use a comma (",") as a decimal seperator. 在法国,他们使用逗号(“,”)作为十进制分隔符。

Will I write 我会写吗

const double x = 100.25 const double x = 100.25

or 要么

const double x = 100,25 const double x = 100,25

Thank you 谢谢

You write programs in C#, not in English. 您使用C#而不是英语编写程序。 Use syntax of C#. 使用C#的语法。

const float x = 100.25

When you show some information for non-Englsih user you can format it in appropriate view. 当显示非英国用户的某些信息时,可以在适当的视图中设置其格式。

For ex.: 例如:

MessageBox.Show(x.ToString().Replace(".", ",")); // or some special format functions

The first. 首先。 There are no cultural variants of C# compiler, the code is compilable by any compiler. C#编译器没有文化上的变体,任何编译器都可以编译该代码。 Besides that, , has some different usages in C# that would be incompatible, eg separating entries in new List: 除此之外, ,在C#中的一些不同的用途,这将是不兼容的,例如,在新的列表条目分离:

var data = new List<double> { 1.0, 2.0, 3.0 };

They will have to write 100.25 too. 他们也必须写100.25 The source code itself is independent of culture. 源代码本身独立于文化。 If this wasn't the case, you'd need some way to specify the culture to the compiler. 如果不是这种情况,则需要某种方式为编译器指定区域性。

Programmers could declare the values as strings and then use double.Parse with an appropriate format provider, but that would be a runtime conversion and an inefficient way to declare values known at compile time. 程序员可以将值声明为字符串,然后使用适当的格式提供程序使用double.Parse ,但这将是运行时转换,并且是在编译时声明已知值的低效方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM