如何在c#中添加浮点数 [英] How to add floating point numbers in c#

查看:188
本文介绍了如何在c#中添加浮点数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我添加两行包含浮点数并将它们放入不同的行



我使用以下代码来执行此操作





xlWorkSheet1.Cells [i,5] = float(Convert.ToInt32(row [13])+ Convert.ToInt32(row1 [13]));



但我得到了以下错误:



Error1无效的表达式术语'浮动'





任何人都可以帮我解决这个问题





谢谢

John

解决方案

尝试:

 xlWorkSheet1.Cells [i,5] =(float)(Convert.ToInt32(row [13])+ Convert.ToInt32 (row1 [13])); 



但是有没有理由将它们首先转换为整数?如果将它们转换为浮点数或双值而不是更明显吗?


转换此行也是浮点类型

xlWorkSheet1.Cells [i,5 ])







这样写(浮动)


< blockquote>编译器错误CS1525意味着您不太了解投射。您可以通过(浮点数)而不是浮点数来修复它。关于错误CS1525的更清楚,见下文。

http://msdn.microsoft.com/en-us/library/3hdyz4dw(v=vs.90).aspx [ ^ ]


Hi,

I am adding two rows which contain floating point numbers and placing them into different row

I am using following code to do that


xlWorkSheet1.Cells[i, 5] = float(Convert.ToInt32(row[13]) + Convert.ToInt32(row1[13]));

But I am getting following error:

Error1 Invalid expression term 'float'


Can anyone help me in solving this


Thanks
John

解决方案

Try:

xlWorkSheet1.Cells[i, 5] = (float)(Convert.ToInt32(row[13]) + Convert.ToInt32(row1[13]));


But is there a reason why you are converting them to integer first? Wouldn't it be more obvious if you converted them to float or double values instead?


convert this row also float type
xlWorkSheet1.Cells[i, 5])

or

write like this(float)


Compiler Error CS1525 means you didn't well know about casting. You can fix it by (float) instead of float. More clearly about Error CS1525, see below.
http://msdn.microsoft.com/en-us/library/3hdyz4dw(v=vs.90).aspx[^]


这篇关于如何在c#中添加浮点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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