在CTYPE和放大器的本地化/全球化问题;的ToString [英] Questions on localization/globalization of Ctype & .ToString

查看:203
本文介绍了在CTYPE和放大器的本地化/全球化问题;的ToString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要回答一些问题,帮助调试问题我在全球化/本地化了的离开了我,而难住了。

A few questions I need answered to help debug an issue I'm having with globalization/localization that's leaving me rather stumped.

1)究竟如何 CTYPE 工作,如果我字符串转换成一个双,当涉及到全球化/本地化?

1) How exactly does CType work if I convert a string into a double when it comes to globalization/localization?

从我的研究,并要求其他开发人员在办公室,我觉得CTYPE应该使用任何区域性设置您的计算机上。因此,例如 CTYPE(1.23,双人间)将正常工作为美国文化的计算机。但它会搞砸通过将其转换为 123 上说一个荷兰的文化计算机,其中是公认的小数点和是公认的千位分隔符。但是,如果字符串是 1,23 ,那么它会正常工作荷兰的计算机上,并成为 123 在美国计算机。

From my research, and asking other developers in the office, I think CType should use whatever culture settings you have on your computer. So for example CType("1.23", Double) would work fine for a US culture computer. But it would mess up by converting it to 123 on say a Netherland's culture computer where , is recognized as the decimal point and . is recognized as the thousand separator. But if the string was 1,23, then it would work fine on the Netherlands computer and become 123 on the US computer.

2)如何做的ToString ,如果我抢了许多工作,并说 doubleNumber.ToString 将其转换为字符串?

2) How does .ToString work if I grab a number and say doubleNumber.ToString to convert it to a string?

在这里我的经验,我99.9%肯定不应该有千位分隔符包括在内,所以一些像 1,234.56 将变成 1234.56 美国计算机上,是否正确?和荷兰文化的计算机数量将成为 1234,56 ,因为上的小数位,对吧?

From my experience here, I'm 99.9% sure that there should be no thousand separators included, so a number like 1,234.56 would be turned into 1234.56 on a US computer, correct? And on a Netherlands culture computer that number would become 1234,56 because , is the decimal place, right?

3)是否有荷兰文化的计算机的办法CTYPE(#,双人间)的ToString 上一个双能以某种方式陷入困境,并开始认识到作为小数点分隔符,而不是一个像荷兰的文化是应该认识?

3) Is there a way on a Netherlands culture computer that CType(#, Double) or .ToString on a double could somehow mess up and start recognizing . as the decimal separator instead of a , like Netherland culture is supposed to recognize?

底线:物品#3是在那里我有我的问题。 99.9%的我的用户,美国和其他国家,可以在没有任何本地化问题上运行我的软件精品。但在荷兰的用户报告了一个错误导入数从 TXT 文件莫名其妙地被转换 1,23 123 。当我们的客户支持人员的人告诉他们到小数点更改为它工作得很好。简短的荷兰用户由于某种原因,用美国文化的计算机(这是他们坚持他们没有)我无法弄清楚这个问题是如何产生的。

Bottom Line: Item #3 is where I'm having my problem. 99.9% of my users, US and foreign, can run my software fine without any localization issues. But a user in the Netherlands reported a bug where importing a number from a txt file somehow was converting 1,23 into 123. When one of our customer support people told them to change the decimal point to a . it worked fine. Short of that Netherlands user for some reason using a US culture computer (which they insist they were not) I can't figure out how this issue is occurring.

推荐答案

你是对你的假设。 .NET将使用当前计算机的文化。

You are right in your assumptions. .NET will use the culture of the current computer.

要应用特定文化的方法是:

The way to apply a specific culture is:

Dim str As String = "97.9"
Dim num As Double = Double.Parse(str, Globalization.CultureInfo.InvariantCulture)

和同一个数字转换为字符串:

And the same to convert a number to string:

num = 97.9
str = num.ToString(Globalization.CultureInfo.InvariantCulture)

您可以指定需要的文化,看到这样的 MSDN文档

You can specify the needed culture, see this MSDN Documentation.

这篇关于在CTYPE和放大器的本地化/全球化问题;的ToString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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