科学计数法的转换和输出
This commit is contained in:
parent
2e47ddb944
commit
9cdd8ae550
|
@ -175,20 +175,19 @@ public class BigDecimalDemoUnitTest {
|
||||||
@Test
|
@Test
|
||||||
public void bigDecimalScientificNotation() {
|
public void bigDecimalScientificNotation() {
|
||||||
// Create a BigDecimal object
|
// Create a BigDecimal object
|
||||||
BigDecimal a;
|
BigDecimal bigNumber;
|
||||||
|
|
||||||
// Create a String object
|
// Create a String object
|
||||||
String s;
|
String numberStr;
|
||||||
|
|
||||||
// Set precision to 5
|
// Set precision to 5
|
||||||
MathContext mc = new MathContext(5);
|
MathContext mc = new MathContext(6);
|
||||||
|
|
||||||
a = new BigDecimal("4536785E4", mc);
|
bigNumber = new BigDecimal(RandomStringUtils.randomNumeric(10)+"E5", mc);
|
||||||
|
|
||||||
// apply toString() method
|
// apply toString() method
|
||||||
s = a.toString();
|
logger.info("{}", bigNumber.toString());
|
||||||
|
logger.info("{}", bigNumber.toEngineeringString());
|
||||||
// print the result
|
logger.info("{}", bigNumber.toPlainString());
|
||||||
System.out.println(s);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue