将长字符串转换为整数 [英] Convert a long string to an integer
问题描述
你好,
我需要将长度等于24的字符串转换为整数.
Convert.ToInt32()
对我不起作用,它引发以下错误:
对于Int32,值太大或太小.
我尝试了Convert.ToInt64()
,它显示了相同的错误.
我需要此转换以进行数值比较.转换不必是整数类型.
任何想法如何解决这个问题?
谢谢
Hello,
I need to convert a string of length equals to 24 to an integer.
Convert.ToInt32()
isn''t working for me, its throwing the following error:
Value was either too large or too small for an Int32.
I tried Convert.ToInt64()
and it showed the same error.
I need this conversion for numerical comparisons. The conversion doesn''t need to be to an integer type.
Any idea how to resolve this issue?
Thank you
推荐答案
您可以尝试使用 C# BigInteger类 [ ^ ].
You could try something like the C# BigInteger Class[^].
您所指的是以下内容:
C#
int @int = int.Parse("123456789009876543211234");
VB.NET
Dim int As Integer = Integer.Parse("123456789009876543211234")
Is this what your referring to:
C#
int @int = int.Parse("123456789009876543211234");
VB.NET
Dim int As Integer = Integer.Parse("123456789009876543211234")
将其转换为双精度
Convert it to a double
string test = "0123456789012345678901234567890";
double dTest = Convert.ToDouble(test);
这会产生1.2345678901234568E+29
精度问题,但是...
this will produce 1.2345678901234568E+29
precision could be a problem however...
这篇关于将长字符串转换为整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!