Gui stuff like scientific notation is extremely ugly. If you don't bother to deal with this data problem. The result was maddening.
There should be a tool class to turn around. This TMD JAVA did not have a toolkit to turn it around. Toss and toss for these low-level things every day.
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;
public class ParseNumber {
public static String scientificNotation2String(Double d, int newValue) {
String value = null;
NumberFormat nf = NumberFormat.getInstance() ;
// Set no grouping in this format
nf.setGroupingUsed(false);
// Set the maximum number of digits allowed in the fractional part of the number.
nf.setMaximumFractionDigits(newValue);
value = nf.format(d);
return value;
}
public static String scientificNotation2String(Double d) {
String value = null;
DecimalFormat decimalFormat = new DecimalFormat("0.00");// Formatting
value = decimalFormat.format(d);
return value;
}
public static String scientificNotation2String(String str) {
String value = null;
BigDecimal bd = new BigDecimal(str );
value = bd.toPlainString();
return value;
}
public static void main(String[] args) {
// TODO Auto-generated method stub //When the number of digits in the integer part is greater than or equal to 8, the System
will be displayed in scientific notation
.out.println(-12345678.0);
System.out.println(12345678.0);
//Integer bit is 0, when the decimal place starts from 0 and is greater than or equal to 3, it starts to display in scientific notation
System.out.println(0.0001 );
System.out.println(-0.0001);
}
}
I would like to thank Xiaozan's technical garden for summarizing and summarizing these methods.
scientific notation conversion class
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=326246890&siteId=291194637
Recommended
Ranking