公告
财富商城
积分规则
提问
发文
2019-01-17 20:06发布
何必那么认真
This question already has an answer here:
For example I need 5.0 to become 5, or 4.3000 to become 4.3.
5.0
5
4.3000
4.3
You should use DecimalFormat("0.#")
DecimalFormat("0.#")
For 4.3000
Double price = 4.3000; DecimalFormat format = new DecimalFormat("0.#"); System.out.println(format.format(price));
output is:
In case of 5.000 we have
Double price = 5.000; DecimalFormat format = new DecimalFormat("0.#"); System.out.println(format.format(price));
And the output is:
Use a DecimalFormat object with a format string of "0.#".
Use DecimalFormat
double answer = 5.0; DecimalFormat df = new DecimalFormat("###.#"); System.out.println(df.format(answer));
最多设置5个标签!
You should use
DecimalFormat("0.#")
For
4.3000
output is:
In case of 5.000 we have
And the output is:
Use a DecimalFormat object with a format string of "0.#".
Use DecimalFormat