2017-05-31 15 views
1

私のアプリケーションでは、浮動小数点数を最も近い整数に変換して調整する必要があります。 4フローティング部分を次の整数値に調整する方法

から6

4.32から5

5.767に例

5.430の場合

どのように私はこれはアンドロイドにアーカイブすることができます??

私は既にmath.ceil()とmath.nextup()関数を使用しています。しかし、それは動作していません

+0

これを取得しようとしましたか? – Sree

+0

を参照してくださいhttps://stackoverflow.com/questions/8753959/round-a-floating-point-number-to-the-next-integer-value-in-java?rq=1 – Redman

+0

[ Javaの次の整数値へのポイント番号の変換](https://stackoverflow.com/questions/8753959/round-a-floating-point-number-to-the-next-integer-value-in-java) –

答えて

1

を使用するMath#round(float a)は、浮動小数点を最も近い整数に丸めます。

0
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)); 
    } 
} 
関連する問題