将字符串转换为double [英] Casting a string to a double

查看:95
本文介绍了将字符串转换为double的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试这样做:

Double myDouble

myDouble =(double)myString


我有确保myString具有有效值,即79.46。但是编译器

不会让我做演员。


如何将值输入myDouble。


谢谢,


T

I''m trying to do this:
Double myDouble
myDouble = (double) myString

I have ensured that myString has a valid value i.e. 79.46. But the compiler
won''t let me do the cast.

How can I get the value into myDouble.

Thanks,

T

推荐答案

试试这个:

myDouble = Double.Parse();


确保当然可以处理任何可能的错误。请查看

文件。


Tina < TI ********** @ nospammeexcite.com>在留言中写道

news:%2 ****************** @ TK2MSFTNGP02.phx.gbl ...
Try this:

myDouble = Double.Parse();

Make sure to handle any possible errors of course. look it up in
documention.

"Tina" <ti**********@nospammeexcite.com> wrote in message
news:%2******************@TK2MSFTNGP02.phx.gbl...
我正在尝试这样做:
双myDouble
myDouble =(double)myString

我确保myString有一个有效值,即79.46。但是
编译器不会让我做演员。

如何将值传入myDouble。

谢谢,

I''m trying to do this:
Double myDouble
myDouble = (double) myString

I have ensured that myString has a valid value i.e. 79.46. But the
compiler won''t let me do the cast.

How can I get the value into myDouble.

Thanks,

T



更喜欢使用double.tryparse而不是因为1.它没有扔掉

2.文化意识


-


________________________

热烈的问候,

Alvin Bruney [MVP ASP.NET]


[无耻作者插件]

专业版VSTO.NET - Wrox / Wiley

OWC使用.NET的黑皮书
www.lulu.com/owc ,亚马逊

博客: http://www.msmvps.com/ blogs / alvin

----------------------------------- --------------------


" Glen Martin" <他********* @ newsgroups.nospam>在消息中写道

新闻:uC ************** @ TK2MSFTNGP04.phx.gbl ...
prefer the use of double.tryparse instead because 1. it doesn''t throw
2. it is culture aware

--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------

"Glen Martin" <He*********@newsgroups.nospam> wrote in message
news:uC**************@TK2MSFTNGP04.phx.gbl...
试试这个:

myDouble = Double.Parse();

确保当然可以处理任何可能的错误。在
文档中查阅。

Tina < TI ********** @ nospammeexcite.com>在消息中写道
新闻:%2 ****************** @ TK2MSFTNGP02.phx.gbl ...
Try this:

myDouble = Double.Parse();

Make sure to handle any possible errors of course. look it up in
documention.

"Tina" <ti**********@nospammeexcite.com> wrote in message
news:%2******************@TK2MSFTNGP02.phx.gbl...
我是试图这样做:
双myDouble
myDouble =(double)myString

我确保myString有一个有效值,即79.46。但是
编译器不会让我做演员。

如何将值传入myDouble。

谢谢,

T
I''m trying to do this:
Double myDouble
myDouble = (double) myString

I have ensured that myString has a valid value i.e. 79.46. But the
compiler won''t let me do the cast.

How can I get the value into myDouble.

Thanks,

T




试试这个

System.String MyString =" ; 123.456" ;;


System.Double MyDouble;


System.Boolean CanBeConverted = System.Double.TryParse(MyString,out

MyDouble);

" Tina" < TI ********** @ nospammeexcite.com> écritdansle message de news:

%2 ****************** @ TK2MSFTNGP02.phx.gbl ...
Try this
System.String MyString = "123.456";

System.Double MyDouble;

System.Boolean CanBeConverted = System.Double.TryParse(MyString, out
MyDouble);
"Tina" <ti**********@nospammeexcite.com> a écrit dans le message de news:
%2******************@TK2MSFTNGP02.phx.gbl...
我正在尝试这样做:
Double myDouble
myDouble =(double)myString

我确保myString有一个有效值,即79.46。但是
编译器不会让我做演员。

如何将值传入myDouble。

谢谢,

T
I''m trying to do this:
Double myDouble
myDouble = (double) myString

I have ensured that myString has a valid value i.e. 79.46. But the
compiler won''t let me do the cast.

How can I get the value into myDouble.

Thanks,

T



这篇关于将字符串转换为double的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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