2012-06-28 15 views
0

我正在做的是這樣的,我離開了5',然後我轉了3 「除以12,然後我用分母除以分子,然後我將它加起來並乘以1.414它的工作原理,但我不知道如何顯示英尺和英寸的分數我如何採取像5'3「1/2的測量,然後乘以1.414,並在Android java上顯示相同格式的答案

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 - 呃......英國在很多年前就開始計量了。 http://en.wikipedia.org/wiki/Metrication_in_the_United_Kingdom#Current_usage現在可以肯定的是,很多人不喜歡它......但你不能取悅每個人。 –

回答

1

這裏是你如何找出英尺和英寸在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 

現在所有剩下要做的就是DISP將rest作爲分數。我不熟悉Android SDK中的內容或不允許的內容,並且有很多方法可以執行此操作(請參閱this answer)。

相關問題