C#转换双精度浮点数错误 [英] C# casting double to float error

查看:97
本文介绍了C#转换双精度浮点数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的代码中,我有以下内容,其中_realScore是浮点数。

In my code I have the following where _realScore is a float.

_realScore=Math.Ceiling(_realScore);

但是出现以下错误
无法将类型'double'隐式转换为'float' 。存在显式转换(是否缺少强制转换?)

But I get the following error Cannot implicitly convert type 'double' to 'float'. An explicit conversion exists (are you missing a cast?)

所以我认为这意味着我必须转换Math.Ceiling的结果以键入float。但是我尝试的都没有。有人可以帮忙吗?

So I assume this means I must cast the result of Math.Ceiling to type float. But nothing I try works. Can anyone help?

推荐答案

您尝试过吗?

_realScore = (float) Math.Ceiling(_realScore);

这篇关于C#转换双精度浮点数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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