fun main() { val c = 0.2 + 0.2.2 val d = 3.5 + 4.3 + 5.1 println(d) // trả về 12.8999999999999 println(c) // trả về 0.42000000000004 }
Kết quả này đúng hay sai ạ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Cái này em code đúng rồi nhé, vì bản chất máy tính không có số thực nó chỉ có nhị phân 1 0 thôi, nên nó cần biểu diễn số thực thông qua chuẩn ví dụ IEEE 754 nên nó sẽ không thể nào đảm bảo chính xác từng dấu phẩy động được. Muốn chính xác dấu phẩy động em phải dùng BigDecimal, ví dụ:
em cảm ơn anh đã giúp em , mấy hôm nay em nghĩ mãi không thông 😂