Go Down

Topic: Converting float into 2 integers (Read 621 times)previous topic - next topic

Joseph_hewitt

Aug 21, 2012, 09:21 pm
Hi, I have a temperature in a float and I was wondering, is it possible to turn that into 2 integers?
for example;

float value = 21.74;

Could I have int A equal 21 and int B equal 74?

Thanks.

Arrch

#1
Aug 21, 2012, 09:24 pm
Getting 21 is as simple as assigning value to an int.

Getting 74 can be achieved by multiplying value by 100, then modulus dividing it by 100.

el_supremo

#2
Aug 21, 2012, 09:26 pm
Assuming that A and B are declared as integers:
Code: [Select]
`A = value;// This rounds up the fractional part of "value"B = (value - A)*100 + 0.5;`

Pete
Don't send me technical questions via Private Message.

Joseph_hewitt

#3
Aug 21, 2012, 09:37 pm

Assuming that A and B are declared as integers:
Code: [Select]
`A = value;// This rounds up the fractional part of "value"B = (value - A)*100 + 0.5;`

Pete

Thanks for your help, that worked perfectly!

Go Up