public
static
void
main(String[] args) {
DecimalFormat df =
new
DecimalFormat(
"###.####"
);
float
f =
20
.0f;
System.out.println(
"你不想要的:"
+ f);
System.out.println(
"你想要的答案:"
+ df.format(f));
}
tring str = "0.000";
Pattern pa1 = Pattern.compile("^[0-9].[1-9]+$");
if(pa1.matcher(str).matches()){
System.out.println(str);
}else{
String s = str.substring(0, str.lastIndexOf("."));
System.out.println(s);
}
float
f =
20
.1f;
int
fi=(
int
)f;
if
(f==fi)
System.out.println(fi);
else
System.out.println(f);