c# 如何将 float 转换为 int

标签 c# floating-point int

我需要将 float 转换为 int(单精度,32 位),例如:
' float :2(十六进制:40000000)到整数:1073741824'。知道如何实现吗?
我在 msdn 帮助中寻找它,但没有结果。

最佳答案

float f = ...;
int i = BitConverter.ToInt32(BitConverter.GetBytes(f), 0);

关于c# 如何将 float 转换为 int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7173677/

相关文章:

mysql - mysql 中 int(11) 列的大小是多少(以字节为单位)?

c# - 如何阻止 SonarLint 抑制的警告不断重新出现在 VS 错误屏幕中

c# - 传递给 MVC Controller 的 id 总是映射为 0

c# - 如何找到一台机器上安装的所有浏览器

php - 使用 "<="或 ">="比较 float 是否理想?

C 基本 scanf 不工作

c# - 如何在 Unity iOS 中正确使用 WebCamTexture?

c - 可以表示为 float 的最大奇数

c - 为什么在 c 中 sizeof(0.7)=8 字节?

java - 在这种情况下(模数和加法之后)是否需要检查零?