0

我正在做的是这个,我不理会 5' 然后我把 3" 除以 12 变成小数点,然后我将分子除以分母,然后我把它全部加起来并乘以 1.414 它可以工作但是我不知道如何显示英尺英寸和几分之一英寸

    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");
4

1 回答 1

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).

于 2012-06-28T02:14:47.563 回答