将string numStr = "1234.56789";分别转换为int ,float , double,并输出结果 将string numStr = "1234.56789";分别转换为int ,float , double,并输出结果 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 强转啊int.parse(numStr.tostring());依次类推 本帖最后由 caozhy 于 2011-07-06 10:12:17 编辑 int.parse(numStr)double.parse(numStr)single.parse(numStr) 不行,出现错误未处理 System.FormatException Message=输入字符串的格式不正确。 Source=mscorlib StackTrace: 在 System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) 在 System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) 在 System.Convert.ToInt32(String value) 在 PB_Topic1_8.Program.Main(String[] args) 位置 E:\1111\111\Topic1\PB_Topic1_8\PB_Topic1_8\Program.cs:行号 16 在 System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) 在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) 在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 在 System.Threading.ThreadHelper.ThreadStart_Context(Object state) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 在 System.Threading.ThreadHelper.ThreadStart() InnerException: 这样也不行,未处理 System.FormatException Message=输入字符串的格式不正确。 Source=mscorlib StackTrace: 在 System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) 在 System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) 在 System.Int32.Parse(String s) 在 PB_Topic1_8.Program.Main(String[] args) 位置 E:\学习\作业\Topic1\PB_Topic1_8\PB_Topic1_8\Program.cs:行号 18 在 System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) 在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) 在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 在 System.Threading.ThreadHelper.ThreadStart_Context(Object state) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 在 System.Threading.ThreadHelper.ThreadStart() InnerException: string numStr = "1234.56789";double d = Convert.ToDouble(numStr);int i = d;float f = (float)d;哎 基本功挺差的昂 string numStr = "1234.56789";double d = Convert.ToDouble(numStr);int i = d;float f = (float)d;楼上这个方法肯定能过,就是准确就达不到那么精确了 谢谢,int i =(int) d;就OK了 C#中对文件操作 C# webservice 怎样分页传送一个数据量较大的DataTable C#中控件的调用问题 求函数调用关系的分析工具 C#中关于限制往listbox中添加重复值的问题!急 数据库连接server=localhost无效 高分求:我想获取本周星期一的是具体日期,可以吗? 如何在虚拟目录下创建可以设置大小的文件夹??? "事务处理","反射",接口" 请问下,多线程处理一个任务 多重if结构报错 SQL 错误,求解
double.parse(numStr)
single.parse(numStr)
不行,出现错误
未处理 System.FormatException
Message=输入字符串的格式不正确。
Source=mscorlib
StackTrace:
在 System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
在 System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
在 System.Convert.ToInt32(String value)
在 PB_Topic1_8.Program.Main(String[] args) 位置 E:\1111\111\Topic1\PB_Topic1_8\PB_Topic1_8\Program.cs:行号 16
在 System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
InnerException:
这样也不行,未处理 System.FormatException
Message=输入字符串的格式不正确。
Source=mscorlib
StackTrace:
在 System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
在 System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
在 System.Int32.Parse(String s)
在 PB_Topic1_8.Program.Main(String[] args) 位置 E:\学习\作业\Topic1\PB_Topic1_8\PB_Topic1_8\Program.cs:行号 18
在 System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
InnerException:
float f = (float)d;哎 基本功挺差的昂
float f = (float)d;楼上这个方法肯定能过,就是准确就达不到那么精确了
谢谢,int i =(int) d;
就OK了