Converting a int value into a decimal one (C++)

Soldato
Joined
10 Apr 2004
Posts
13,497
Im working on an app pulling out FSUIPC data out of FS2004.

I've got a value of 33474 coming out of the sim going into an int (it has to be an int, its 4 byte data...)

But anyway, its 256 times the 'real life' value, so I divide the variable that holds the value of 33474 but I get a value of 130.

Its actually 130.7578125...

I've tried everything I can think of and googled but nothing to allow me to divide to a decimal!! :(

Any help?

PS: Anyone willing enough to help me along the way to learning C++ would be greatly appreciated :p
 
Double d = 33474/256
int i
i = d+0.5

What happens is returning your double to an int, it just ignores anything after the ., so you need to +0.5 in order to get it to round up, to the nearest integer.

I am assuming thats what you need to do - round it back into integer form?
 
Thanks, but as ever just as you post that I fix it by just adding the /256 in the printf bit.

Works perfectly, yay.

Now onto the next problem I guess!

Cheers
 
Back
Top Bottom