Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# how to convert float to int

I need to convert float to int (single precision, 32 bits) like:
'float: 2 (hex: 40000000) to int: 1073741824'. Any idea how to implement that?
I was looking for it in msdn help but with no result.

like image 439
santBart Avatar asked Aug 24 '11 10:08

santBart


1 Answers

float f = ...;
int i = BitConverter.ToInt32(BitConverter.GetBytes(f), 0);
like image 136
David Heffernan Avatar answered Sep 30 '22 01:09

David Heffernan