科学计数法的转换和输出

This commit is contained in:
YuCheng Hu 2020-02-25 10:04:49 -05:00
parent 2e47ddb944
commit 9cdd8ae550
1 changed files with 7 additions and 8 deletions

View File

@ -175,20 +175,19 @@ public class BigDecimalDemoUnitTest {
@Test
public void bigDecimalScientificNotation() {
// Create a BigDecimal object
BigDecimal a;
BigDecimal bigNumber;
// Create a String object
String s;
String numberStr;
// 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
s = a.toString();
// print the result
System.out.println(s);
logger.info("{}", bigNumber.toString());
logger.info("{}", bigNumber.toEngineeringString());
logger.info("{}", bigNumber.toPlainString());
}
}