小数怎么用Convert.toint转化不成整数了????????

sprc_lcl 2006-04-07 03:00:43
try
{
Response.Write("ToDecimal:"+Convert.ToDecimal("1.11").ToString()+"<br>");
}
catch
{}
try
{
Response.Write("ToDouble:"+Convert.ToDouble("1.11").ToString()+"<br>");
}
catch
{}
try
{
Response.Write("ToInt16:"+Convert.ToInt16("1.11").ToString()+"<br>");
}
catch
{}
try
{
Response.Write("ToInt32:"+Convert.ToInt32("1.11").ToString()+"<br>");
}
catch
{}
try
{
Response.Write("ToInt64:"+Convert.ToInt64("1.11").ToString()+"<br>");
}
catch
{}
try
{
Response.Write("ToUInt16:"+Convert.ToUInt16("1.11").ToString()+"<br>");
}
catch
{}

打印结果:
ToDecimal:1.11
ToDouble:1.11

整数怎么会报错?????
...全文
350 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
lonelyair 2006-04-07
  • 打赏
  • 举报
回复
应该直接用小数转化,不是字符串


try
{
Console.WriteLine("ToInt32:" + Convert.ToInt32(1.11).ToString());
Console.ReadLine();
}
catch
{
}
hywyjw 2006-04-07
  • 打赏
  • 举报
回复

float s1;
string sb="";

s1=xxx.xx;
sb=string.Format(sb,s1);
int.Parse(sb);
hywyjw 2006-04-07
  • 打赏
  • 举报
回复

float s1;
string sb="{0}";

sb=string.Format(sb,s1);
int.Parse(sb);
hywyjw 2006-04-07
  • 打赏
  • 举报
回复

float s1;
string sb="";

sb=string.Format(sb,s1);
int.Parse(sb);


你这样试试, 应当行!!!
lonelyair 2006-04-07
  • 打赏
  • 举报
回复
帮忙顶一下
我也试了出错。

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧