字符串转换 [英] string conversion

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

问题描述

我有一个以百分比形式输入的文本框,即

" 100.00%"。如何将其转换为双倍?如果我这样做
System.Convert.ToDouble(MyVar)我得到一个例外。如何剥离

%的签名? (也可能没有%,因为用户可能只是

输入100或100.00)

I have a textbox that is getting input in the form of a percent ie.
"100.00%". How do I convert this to a double? If i do
System.Convert.ToDouble(MyVar) I get an exception. How do I strip the
percent sign off? (Also there may not be a % because the user may just
enter 100 or 100.00)

推荐答案

David A. Osborn <做******** @ hotmail.com>在新闻中写道:un%te.91194
"David A. Osborn" <do********@hotmail.com> wrote in news:un%te.91194


nG6.21524@attbi_s22:
nG6.21524@attbi_s22:
我有一个以百分比形式输入的文本框即。
100.00%。如何将其转换为双倍?如果我做了./ System>Convert.ToDouble(MyVar)我得到一个例外。如何剥离
百分号? (也可能没有%,因为用户可能只是输入100或100.00)
I have a textbox that is getting input in the form of a percent ie.
"100.00%". How do I convert this to a double? If i do
System.Convert.ToDouble(MyVar) I get an exception. How do I strip the
percent sign off? (Also there may not be a % because the user may just
enter 100 or 100.00)




十进制x = decimal.Parse(textBox.Text.Replace ("%",""));


它的C#,但你得到了重点。

-

Chad Z. Hower(又名Kudzu) - http://www.hower。 org / Kudzu /

编程是一种反击的艺术形式


使用IntraWeb让你的ASP.NET运转起来! br /> http://www.atozed.com/IntraWeb/


嗨大卫! :O)


尝试这样的事情:

''***

Dim s As String =" 100.00%

Dim d As Double = Double.Parse(s.Replace("%",""),

CultureInfo.InvariantCulture)

Console.WriteLine(d)

''***


-

最好的问候

Yanick

" David A. Osborn" <做******** @ hotmail.com> écritdansle message de

news:un%te.91194
Hi David ! :O)

Try something like this :
''***
Dim s As String = "100.00%"
Dim d As Double = Double.Parse(s.Replace("%", ""),
CultureInfo.InvariantCulture)
Console.WriteLine(d)
''***

--
Best Regards
Yanick
"David A. Osborn" <do********@hotmail.com> a écrit dans le message de
news:un%te.91194


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

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