Bài viết này sẽ hướng dẫn cách chuyển đổi kiểu dữ liệu DOUBLE làm tròn lên thành kiểu dữ liệu INT trong ngôn ngữ lập trình java.
ConvertDoubleToIntRoundUp.java
/**
* @(#)ConvertDoubleToIntRoundUp.java
*
* ConvertDoubleToIntRoundUp application
*
* @author BUI NGOC SON
* @version 1.00 2013/12/5
*/
public class ConvertDoubleToIntRoundUp {
public static void main(String[] args) {
// TODO, add your application code
int variable_01 = (int) Math.ceil(4.99999); //gives 5 only
int variable_02 = (int) Math.ceil(4.11111); //gives 4 only
System.out.println("Variable 01: " + variable_01);
System.out.println("Variable 02: " + variable_02);
System.out.println("\n \n VNLIVES.NET");
}
}
* @(#)ConvertDoubleToIntRoundUp.java
*
* ConvertDoubleToIntRoundUp application
*
* @author BUI NGOC SON
* @version 1.00 2013/12/5
*/
public class ConvertDoubleToIntRoundUp {
public static void main(String[] args) {
// TODO, add your application code
int variable_01 = (int) Math.ceil(4.99999); //gives 5 only
int variable_02 = (int) Math.ceil(4.11111); //gives 4 only
System.out.println("Variable 01: " + variable_01);
System.out.println("Variable 02: " + variable_02);
System.out.println("\n \n VNLIVES.NET");
}
}
Dưới đây là kết quả sau khi chạy chương trình.
No comments:
Post a Comment