Вопрос

I'm using DecimalFormat in order to convert double to string like this:

DecimalFormat df = new DecimalFormat("###.###");

df.format(km);

The problem is, although the variable km has the value of 9.655195710258606E-5, the result of the df.format method returns 0 as string.But I expect something like 9.655 instead of 0.

Any help & suggestions will be appreciated

Thank you for your concern

Это было полезно?

Решение

It works as it should. The string "9.655" would be wrong. The value is actually 0.00009655 and if you round it to 3 decimal places you get "0".

To see some more digits, you can use more decimal places in the format #.###### or force scientific notation with a format like this #.###E0.

Другие советы

In the end of these numbers, the E(x) represents the exponent. E-5, means the exponent is -5, which means the actual number is 9.655 * (1/(10^5)).

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top