2010-01-26 99 views
1

我會如何將測量值從12.5英尺轉換爲12英尺6英寸?如何創建第二個數字,乘以12時只讀取小數位?將小數點英尺轉換爲英尺和英寸?

現在我有使用其他變量和一些數學雙Measurement01讓我的腳在小數。我用farf.setText(Measurement01 +「」+「ft」)將它發送到textview;

任何幫助,將不勝感激!

回答

7

的。減去整數部分:

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

@ Ry4an的答案建立在:

//... 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" : "")); 
1

很簡單,這裏length是浮點長度:

int feet = (int)length; 
int inches = (length - feet) * 12.0; 
: : 
farf.setText (feet + " ft, " + inches + " inches"); 
相關問題