0
double totalInches = d * 0.3937;
double feetPart = totalInches / 12;
int inchesPart = (int) Math.ceil(totalInches - (feetPart * 12));
return (feetPart) + "' " + inchesPart + "''";

値を取得しています6.9999999 ' 0"。文字列を返しています。これが、フィート単位の小数の値が丸められない理由ですか。

私もキャストせずに試しました。double inchesPart = Math.ceil(totalInches - (feetPart * 12));、それでも同じ結果が得られます。

4

2 に答える 2

5

確かにあなたは必要です:

int feetPart = (int)Math.floor(totalInches / 12);

あるいは単に:

int feetPart = (int)(totalInches / 12);

于 2013-04-17T14:51:28.587 に答える