views:

417

answers:

4

How would I go about converting a measurement from, for example, 12.5 feet to 12ft 6in? How would I created that second number which reads only the decimal place when multiplying by 12?

right now I have double Measurement01 using other variables and some math to get me the feet in decimals. I send that to a textview with farf.setText(Measurement01 + " " + "ft");

Any help would be appreciated!

+1  A: 

Grab the decimal part, then multiply by 12.

Anon.
That's exactly what he's asking how to do.
danben
+6  A: 

Substract the integer portion:

float measurement = 12.5;
int feet = (int)measurement;
float fraction = measurement - feet;
int inches = (int)(12.0 * fraction);
Ry4an
A: 

Building on @Ry4an's answer:

//... Other code above

float Measurement01 = 12.5;
int feet = (int)Measurement01;
float fraction = Measurement01 - feet;
int inches = (int)(12.0 * fraction);

// Display like: 2.5 = 2 ft 6 in, 0.25 = 3 in, 6.0 = 6 ft
farf.setText((0 != feet ? feet + " ft" : "") + (0 != inches ? " " + inches + " in" : "")); 
Buckwad
+1  A: 

Quite simply, where length is the floating point length:

int feet = (int)length;
int inches = (length - feet) * 12.0;
: :
farf.setText (feet + " ft, " + inches + " inches");
paxdiablo