2012-06-28 5 views
0

내가 무엇을하고있는이 동일한 형식으로 대답을 표시, 나는 혼자서 5'혼자두고 떠난다. "12로 나누면 십진수로 나눈 다음 분자를 분모로 나눕니다. 그리고 나서 그것을 모두 더하고 1.414를 곱하면됩니다. 그러나 나는 피트의 인치와 분수를 어떻게 표현할 지 알지 못합니다.어떻게 5 '3 "1/2 같은 측정을하고 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"); 
+1

... 아이들이 미국과 영국을 제외한 나머지 국가들이 측정 기준을 얻은 이유입니다 ... ;-) –

+1

@aamos - ermm ... 영국은 수년 전에 측정 기준을 통과했습니다. http://en.wikipedia.org/wiki/Metrication_in_the_United_Kingdom#Current_usage 이제 많은 사람들이 그것을 좋아하지 않았지만 모든 사람을 기쁘게 할 수는 없습니다. –

답변

1

는 자바 발과 인치을 계산하는 방법은 다음과 같습니다

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 

을 지금 할 남아있는 모든이 DISP입니다 rest을 분수로 둡니다. Android SDK에서 무엇이 허용되는지 또는 허용되지 않는지 익숙하지 않으며,이를 수행 할 수있는 여러 가지 방법이 있습니다 (this answer 참조).