Mohsen Sarkar
Mohsen Sarkar

Reputation: 6030

How to convert float to int without losing the decimal ? Just like it's shown in memory

Let's assume float f = 4.4

If I browse f in some memory reader and assume that f is an int I get the value 1082969293.

I don't want to cast it to int like (int)f

Is there a way to assume f as int and get that value(1082969293) in C# ?

Upvotes: 1

Views: 214

Answers (1)

Lee
Lee

Reputation: 144136

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

Upvotes: 8

Related Questions