Java decimal precision problem
•
Java
I have a problem. I have to print in long decimal places
Solution
In C or Java, you won't get so much decimal precision in IEEE754 binary floating point numbers Your best choice is to use BigDecimal and perform arithmetic with specific precision For example:
import java.math.*; public class Test { public static void main(String[] args) throws Exception { MathContext context = new MathContext(30); BigDecimal result = BigDecimal.ONE.divide(new BigDecimal(3),context); System.out.println(result.toPlainString()); } }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码