This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Utils { | |
public static void main(String[] args) { | |
//Trunca los decimales. | |
double d = 1234.56; | |
long x = (long) d; | |
System.out.println(x); | |
//Redondea los decimales | |
d = 1234.56; | |
x = Math.round(d); | |
System.out.println(x); | |
} | |
} |
Si se castea simplemente se truncaran los decimales. Si se utiliza el método round utilizará técnicas de redondeo. El código anterior devolvería lo siguiente:
1234
1235