0

what I'm doing is this, I leave the 5' alone then I turn 3" into a decimal of a foot by dividing by 12 then I divide the numerator by the denominator then I add it all up and multiply by 1.414 it works but I dont know how I would display the foot inches and fraction of a inch

    c2c_fdecimal = f_num / f_den;
    c2c_fdeci_fft = c2c_fdecimal / 12.0;
    deci_of_foot = inchs / 12.0;
    total_travel= feet + c2c_fdeci_fft + deci_of_foot;

    toff_ftodeci = tkoff_numa / tkoff_dena;
    tkoff_inch = tkoff_inch / 12.0;
    sub_toff = toff_ftodeci / 12.0 + tkoff_inch;
    ans = (total_travel * ffformula) - sub_toff;
    //print out measurement format
    ansint = (int)ans;
    strip_inches = (int) ((ans - ansint) * 12.0); 
    //print answer
    editText2.setText(ansint + " ft" + strip_inches + " in");
TylerH
  • 20,799
  • 66
  • 75
  • 101
  • 1
    ... and that, children, is why the rest of the world (except US and UK) has gone metric... ;-) – Amos M. Carpenter Jun 28 '12 at 02:31
  • 1
    @aamos - ermm ... the UK went metric many years ago. http://en.wikipedia.org/wiki/Metrication_in_the_United_Kingdom#Current_usage Now admittedly a lot of people didn't like it ... but you can't please everyone. – Stephen C Jun 28 '12 at 03:45
  • The US also went metric in 1975 – TylerH Aug 30 '22 at 16:15

1 Answers1

1

Here's how you'd figure out the feet and inches in Java:

double resultInInches; // you start with inches...
int feet = (int)(resultInInches / 12);
double rest = (resultInInches / 12) - feet;
int wholeInches = (int)rest;
rest = rest-wholeInches; // rest now holds the fraction of the inch, eg 0.4141

Now all that's left to do is display rest as a fraction. I'm not familiar with what is or is not permitted in the Android SDK, and there's a bunch of ways to do this (see this answer).

Community
  • 1
  • 1
Roddy of the Frozen Peas
  • 14,380
  • 9
  • 49
  • 99