Java - Chuyển đổi DOUBLE thành INT làm tròn xuống (Convert DOUBLE to INT round down in java).






Bài viết này sẽ hướng dẫn cách chuyển đổi kiểu dữ liệu DOUBLE thành kiểu dữ liệu INT được làm tròn xuống trong ngôn ngữ lập trình java.








ConvertDoubleToIntRoundDown.java
/**
 * @(#)ConvertDoubleToIntRoundDown.java
 *
 * ConvertDoubleToIntRoundDown application
 *
 * @author BUI NGOC SON
 * @version 1.00 2013/12/5
 */

public class ConvertDoubleToIntRoundDown {
   
    public static void main(String[] args) {
       
        // TODO, add your application code
        int variable_01 = (int) 4.99999;   //gives 4 only
        int variable_02 = (int) 4.11111;   //gives 4 only
               
        System.out.println("Variable 01: " + variable_01);
        System.out.println("Variable 01: " + 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