Convert.ToDouble()问题 [英] Convert.ToDouble() problem

查看:83
本文介绍了Convert.ToDouble()问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在调用Convert.ToDouble(someString);


但是这个双倍可以有方法或代表双重依赖于

locale,它可以是1.0或1,0


有没有办法让Convert.ToDouble(..)同时接受逗号和句号

表示数字的符号?


感谢

Hey
I am calling Convert.ToDouble(someString);

But this double can have to ways or representing doubles dependant on the
locale, it can be 1.0 or 1,0

Is there a way to make Convert.ToDouble(..) accept both comma and period
notations for representing numbers?

thanks

推荐答案



<二******** @ discussion.microsoft.com>在消息中写道

新闻:%2 **************** @ TK2MSFTNGP10.phx.gbl ...

<di********@discussion.microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...


我调用的是Convert.ToDouble(someString);

但是这个double可以用于表示或者表示双精度依赖于
的语言环境,它可以是1.0或1 ,0

有没有办法让Convert.ToDouble(..)同时接受逗号和
句号表示数字?

谢谢
Hey
I am calling Convert.ToDouble(someString);

But this double can have to ways or representing doubles dependant on the locale, it can be 1.0 or 1,0

Is there a way to make Convert.ToDouble(..) accept both comma and period notations for representing numbers?

thanks




我觉得很难。示例:1,000可以是1000美元或者欧洲美元的美国符号1.


如果你知道没有数千个分隔符,那么你可以做一个替换要更改的字符串上的
,进入。 (或者相反)


Hans Kesting



I think it is difficult. Example: "1,000" could be US notation for 1000
or european for 1.

If you know there are no thousands-separators, then you could do a Replace
on the string to change "," into "." (or the other way around)

Hans Kesting




我们有一台带逗号的机器符号和另一个带有周期符号的符号

这个必须适用于两者并且这在许多地方被调用。


实现我自己的Convert.ToDouble( ..)似乎是唯一简单的方法。


是否可以使用ToDouble

方法中的IFormatProvider参数执行此操作?

" Hans Kesting" <是ne *********** @ spamgourmet.com>在消息中写道

news:ep ************** @ TK2MSFTNGP12.phx.gbl ...

We have one machine with comma notation and the other with period notation
and this must work on both and this is being called in lots of places.

Implementing my own Convert.ToDouble(..) seems to be the only easy way.

Is it possible to do this with IFormatProvider parameter in the ToDouble
method?
"Hans Kesting" <ne***********@spamgourmet.com> wrote in message
news:ep**************@TK2MSFTNGP12.phx.gbl...

< ;二******** @ discussion.microsoft.com>在消息中写道
新闻:%2 **************** @ TK2MSFTNGP10.phx.gbl ...

<di********@discussion.microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...


我正在调用Convert.ToDouble(someString);

但是这个双重可以有方法或代表双重依赖于
Hey
I am calling Convert.ToDouble(someString);

But this double can have to ways or representing doubles dependant on


locale,它可以是1.0或1,0

有没有办法让Convert.ToDouble(..)接受逗号和
locale, it can be 1.0 or 1,0

Is there a way to make Convert.ToDouble(..) accept both comma and


句号

表示数字的符号?

感谢
notations for representing numbers?

thanks



我觉得很难。示例:1,000可能是1000美元的美国符号或者1的欧洲符号。

如果你知道没有数千个分隔符,那么你可以在字符串上做一个替换
来改变 ,"进入。 (或者相反)

Hans Kesting



I think it is difficult. Example: "1,000" could be US notation for 1000
or european for 1.

If you know there are no thousands-separators, then you could do a Replace
on the string to change "," into "." (or the other way around)

Hans Kesting






< di ******** @ discussion.microsoft.com>在消息中写道

新闻:%2 **************** @ TK2MSFTNGP10.phx.gbl ...
Hi,

<di********@discussion.microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...


我调用的是Convert.ToDouble(someString);

但是这个double可以用于表示或者表示双精度依赖于
的语言环境,它可以是1.0或1 ,0

有没有办法让Convert.ToDouble(..)接受逗号和
周期表示法来表示数字?
Hey
I am calling Convert.ToDouble(someString);

But this double can have to ways or representing doubles dependant on the locale, it can be 1.0 or 1,0

Is there a way to make Convert.ToDouble(..) accept both comma and period notations for representing numbers?




正如汉斯指出的那样,Convert.ToDouble不知道逗号实际上是什么意思

意味着(数千个分隔符或整个部分/小数部分分隔符)没有

一些额外的帮助。好消息是,将文化考虑在内的是否存在过多的转换.Bt.BoDouble。例如:


double someValue = Convert.ToDouble(someImput,

CultureInfo.CurrentCulture)


虽然上面将使用用户默认文化(如果你正在解析用户输入,可能是正确的

选项),你可以传递你需要的任何文化。


问候,

Dan



As Hans pointed out, Convert.ToDouble can''t know what the comma actually
means (thousands seperator or whole part/decimal part seperator) without
some extra help. The good news is that there is an overload to
Convert.ToDouble that takes culture into account. For example:

double someValue = Convert.ToDouble(someImput,
CultureInfo.CurrentCulture)

Although the above will use the user default culture (probably the right
choice if you are parsing user input), you can pass any culture you need to.

Regards,
Dan


这篇关于Convert.ToDouble()问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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