Let Double type full display without scientific notation display E (Java)

Reprinted from -  https://www.cnblogs.com/gitkoot/p/5433273.html

 

Today, when dealing with bug B2B projects and found that I post items to the background of the tax price is actually contained 12345666661E10 such, is of type String pass past

If not treated this background, so there is certainly a problem with the database field.

  I take this approach code is as follows: - This is taken directly from the code

private BigDecimal totalAmount = new BigDecimal(0);
new BigDecimal(new Double(totalAmount.doubleValue()).toString())

I checked some programs are such a big deal as follows:

 
DecimalFormat df = new DecimalFormat("0");   
  Double d = new Double("1.2345666661E10");  
  System.out.println(df.format(d));
 

This way there is a problem, is not retained after the decimal point decimal places.

My approach is to retain decimal places, specific detailed as follows:

BigDecimal bigDecimal = new BigDecimal("1.2345666666E10");  
        String result = bigDecimal.toString();

In addition, I will be online to modify the program code is as follows:

DecimalFormat df = new DecimalFormat();
df.setMaximumFractionDigits(2);//这里是小数位   
  Double d = new Double("1.2345666661E10");  
  System.out.println(df.format(d));

This program has not been fully tested, if you have different ideas together to exchange!

Guess you like

Origin www.cnblogs.com/kyrie211/p/11204872.html