1
私のアプリケーションでは、浮動小数点数を最も近い整数に変換して調整する必要があります。 4フローティング部分を次の整数値に調整する方法
から6
4.32から5
5.767に例
5.430の場合
どのように私はこれはアンドロイドにアーカイブすることができます??
私は既にmath.ceil()とmath.nextup()関数を使用しています。しかし、それは動作していません
私のアプリケーションでは、浮動小数点数を最も近い整数に変換して調整する必要があります。 4フローティング部分を次の整数値に調整する方法
から6
4.32から5
5.767に例
5.430の場合
どのように私はこれはアンドロイドにアーカイブすることができます??
私は既にmath.ceil()とmath.nextup()関数を使用しています。しかし、それは動作していません
を使用するMath#round(float a)
は、浮動小数点を最も近い整数に丸めます。
public class MathDemo {
public static void main(String[] args) {
// get two double numbers
double x = 60984.1;
double y = -497.99;
double x1 = 125.9;
double y1 = 0.4873;
// call ceal for these these numbers
System.out.println("Math.ceil(" + x1 + ")=" + Math.ceil(x1));
System.out.println("Math.ceil(" + y1 + ")=" + Math.ceil(y1));
System.out.println("Math.ceil(-0.65)=" + Math.ceil(-0.65));
// call floor and print the result
System.out.println("Math.floor(" + x + ")=" + Math.floor(x));
System.out.println("Math.floor(" + y + ")=" + Math.floor(y));
System.out.println("Math.floor(0)=" + Math.floor(0));
}
}
これを取得しようとしましたか? – Sree
を参照してくださいhttps://stackoverflow.com/questions/8753959/round-a-floating-point-number-to-the-next-integer-value-in-java?rq=1 – Redman
[ Javaの次の整数値へのポイント番号の変換](https://stackoverflow.com/questions/8753959/round-a-floating-point-number-to-the-next-integer-value-in-java) –