本文介绍了JAVA如何从double中删除尾随零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,我需要 5.0
成为 5
,或 4.3000
成为 4.3
。
For example I need 5.0
to become 5
, or 4.3000
to become 4.3
.
推荐答案
使用
double answer = 5.0;
DecimalFormat df = new DecimalFormat("###.#");
System.out.println(df.format(answer));
这篇关于JAVA如何从double中删除尾随零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!