2017-05-31 3 views
1

Für meine Anwendung muss eine Floating-Zahl in die nächste Ganzzahl konvertiert und angepasst werden.So passen Sie den Floating-Part an den nächsten ganzzahligen Wert an

Zum Beispiel

5,430 zu 5

5,767 zu 6

4,32 zu 4

Wie kann ich archivieren diese in android ??

Ich habe bereits math.ceil() und math.nextup() Funktion verwendet. Aber es funktioniert nicht

+0

Was haben Sie versucht, dies zu bekommen? – Sree

+0

siehe https://stackoverflow.com/questions/8753959/round-a-floating-point-number-to-the-next-integer-value-in-java?rq=1 – Redman

+0

Mögliches Duplikat von [um ein Floating- Punktnummer auf den nächsten ganzzahligen Wert in Java] (https://stackoverflow.com/questions/8753959/round-a-floating-point-number-to-the-next-integer-value-in-java) –

Antwort

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)); 
    } 
} 
Verwandte Themen