在vb.NET中解析双精度数 [英] Parsing doubles in vb.NET
问题描述
我在解析字符串时遇到问题(来自平面文本输入文件)
加倍。
代码:
currentImportDetail.Result = CType(line.Substring(7,8).Trim(""),
System.Double)
我手表中的内容:
line.Substring(7,8).Trim("")" 0.006000" ;
CType(line.Substring(7,8).Trim("),System.Double)6000.0
System.Decimal.Parse(line.Substring (7,8).Trim(""))6000D
cDec(line.Substring(7,8).Trim(""))6000D
cdbl(line.Substring(7,8).Trim(""))6000.0
我试图使用其他解析方法但由于未知原因结果
是假的,我不知道为什么。
我的区域设置目前是荷兰语(比利时),但是因为他解析了
字符串到6000点0而不是逗号,我怀疑区域设置是
之所以没有像我想要的那样解析我的数据。
Hi,
I''m having a problem parsing strings (comming from a flat text input file)
to doubles.
the code:
currentImportDetail.Result = CType(line.Substring(7, 8).Trim(" "),
System.Double)
What is in my Watch:
line.Substring(7, 8).Trim(" ") "0.006000"
CType(line.Substring(7, 8).Trim(" "), System.Double) 6000.0
System.Decimal.Parse(line.Substring(7, 8).Trim(" ")) 6000D
cDec(line.Substring(7, 8).Trim(" ")) 6000D
cdbl(line.Substring(7, 8).Trim(" ")) 6000.0
I tried to use the other parse methods but for an unknown reason the result
is false and I don''t know why.
My regional settings are currently Dutch(Belgium), but since he parses the
string to 6000 point 0 and not comma, I doubt that the regional settings are
the reason why it isn''t parsing my data like I want.
推荐答案
对于任何有同样问题的人:
解决方案:
尝试使用:line.Substring(7,8).Trim(" ")。替换(。,,,)
亲切的问候,
SL33PY
" SL33PY"写道:
For anyone having the same problem:
the solution:
try using : line.Substring(7, 8).Trim(" ").Replace(".",",")
Kind regards,
SL33PY
"SL33PY" wrote:
我在解析字符串时遇到问题(从平面文本输入文件传来)
到双打。代码:
currentImportDetail.Result = CType(line.Substring(7,8).Trim(""),
System.Double)
<我的手表中有什么:
line.Substring(7,8).Trim("")" 0.006000"
CType(line.Substring(7,8).Trim ("),System.Double)6000.0
System.Decimal.Parse(line.Substring(7,8).Trim(""))6000D
cDec(line.Substring( 7,8).Trim()6000D
cdbl(line.Substring(7,8).Trim(""))6000.0
我试过用其他解析方法,但由于未知原因结果
是假的,我不知道为什么。
我的区域设置目前是荷兰语(比利时),但自从他解析
字符串到6000点0而不是逗号,我怀疑区域设置是否为什么它没有解析我的数据就像我想要的那样。
Hi,
I''m having a problem parsing strings (comming from a flat text input file)
to doubles.
the code:
currentImportDetail.Result = CType(line.Substring(7, 8).Trim(" "),
System.Double)
What is in my Watch:
line.Substring(7, 8).Trim(" ") "0.006000"
CType(line.Substring(7, 8).Trim(" "), System.Double) 6000.0
System.Decimal.Parse(line.Substring(7, 8).Trim(" ")) 6000D
cDec(line.Substring(7, 8).Trim(" ")) 6000D
cdbl(line.Substring(7, 8).Trim(" ")) 6000.0
I tried to use the other parse methods but for an unknown reason the result
is false and I don''t know why.
My regional settings are currently Dutch(Belgium), but since he parses the
string to 6000 point 0 and not comma, I doubt that the regional settings are
the reason why it isn''t parsing my data like I want.
等一下,你想解析一个双? (对不起,如果我误解了b $ b),
你可以:
Double.TryParse(theString)
或
尝试
Double.Parse(theString)
Catch theException as SomeExceptionCantRemember
结束尝试
希望这会有所帮助。
" SL33PY" < SL **** @ discussions.microsoft.com>在消息中写道
新闻:B5 ********************************** @ microsof t.com ...
Hold up a second, you are wanting to parse a double? (sorry if I
misunderstood),
You can:
Double.TryParse(theString)
or
Try
Double.Parse(theString)
Catch theException as SomeExceptionCantRemember
End Try
Hope this helps.
"SL33PY" <SL****@discussions.microsoft.com> wrote in message
news:B5**********************************@microsof t.com...
我在解析字符串时遇到问题(从平面文本输入文件传来)
到双打。代码:
currentImportDetail.Result = CType(line.Substring(7,8).Trim(""),
System.Double)
<我的手表中有什么:
line.Substring(7,8).Trim("")" 0.006000"
CType(line.Substring(7,8).Trim ("),System.Double)6000.0
System.Decimal.Parse(line.Substring(7,8).Trim(""))6000D
cDec(line.Substring( 7,8).Trim()6000D
cdbl(line.Substring(7,8).Trim(""))6000.0
我试过用其他解析方法,但由于未知原因
结果是假的,我不知道为什么。
我的区域设置目前是荷兰语(比利时),但自从他将
字符串解析为6000点0而不是逗号,我怀疑区域设置
是不是我想要解析我的数据的原因。
Hi,
I''m having a problem parsing strings (comming from a flat text input file)
to doubles.
the code:
currentImportDetail.Result = CType(line.Substring(7, 8).Trim(" "),
System.Double)
What is in my Watch:
line.Substring(7, 8).Trim(" ") "0.006000"
CType(line.Substring(7, 8).Trim(" "), System.Double) 6000.0
System.Decimal.Parse(line.Substring(7, 8).Trim(" ")) 6000D
cDec(line.Substring(7, 8).Trim(" ")) 6000D
cdbl(line.Substring(7, 8).Trim(" ")) 6000.0
I tried to use the other parse methods but for an unknown reason the
result
is false and I don''t know why.
My regional settings are currently Dutch(Belgium), but since he parses the
string to 6000 point 0 and not comma, I doubt that the regional settings
are
the reason why it isn''t parsing my data like I want.
Sl33PY,
你能告诉我们字符串的样子吗?
但是,我看到你正在使用带点的字符串作为逗号分隔符。
AFAIK,这是所有三种文化的荷兰语逗号。
Dim dbl As Double = CDbl( " abcd100,10" .Substring(4,5))
这给我100.1
Cor
" SL33PY" < SL **** @ discussions.microsoft.com> schreef in bericht
新闻:B5 ********************************** @ microsof t.com ...
Sl33PY,
Can you give us an idea what the string can looks like?
However, I see that you are using a string with a dot as comma seperator.
AFAIK, is that in the Dutch language for all three cultures a comma.
Dim dbl As Double = CDbl("abcd100,10".Substring(4, 5))
This gives for me 100.1
Cor
"SL33PY" <SL****@discussions.microsoft.com> schreef in bericht
news:B5**********************************@microsof t.com...
我在解析字符串时遇到问题(从平面文本输入文件传来)
到双打。代码:
currentImportDetail.Result = CType(line.Substring(7,8).Trim(""),
System.Double)
<我的手表中有什么:
line.Substring(7,8).Trim("")" 0.006000"
CType(line.Substring(7,8).Trim ("),System.Double)6000.0
System.Decimal.Parse(line.Substring(7,8).Trim(""))6000D
cDec(line.Substring( 7,8).Trim()6000D
cdbl(line.Substring(7,8).Trim(""))6000.0
我试过用其他解析方法,但由于未知原因
结果是假的,我不知道为什么。
我的区域设置目前是荷兰语(比利时),但自从他将
字符串解析为6000点0而不是逗号,我怀疑区域设置
是不是我想要解析我的数据的原因。
Hi,
I''m having a problem parsing strings (comming from a flat text input file)
to doubles.
the code:
currentImportDetail.Result = CType(line.Substring(7, 8).Trim(" "),
System.Double)
What is in my Watch:
line.Substring(7, 8).Trim(" ") "0.006000"
CType(line.Substring(7, 8).Trim(" "), System.Double) 6000.0
System.Decimal.Parse(line.Substring(7, 8).Trim(" ")) 6000D
cDec(line.Substring(7, 8).Trim(" ")) 6000D
cdbl(line.Substring(7, 8).Trim(" ")) 6000.0
I tried to use the other parse methods but for an unknown reason the
result
is false and I don''t know why.
My regional settings are currently Dutch(Belgium), but since he parses the
string to 6000 point 0 and not comma, I doubt that the regional settings
are
the reason why it isn''t parsing my data like I want.
这篇关于在vb.NET中解析双精度数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!