user863873
user863873

Reputation:

Double variable format

I have a the next line :

String.format("%10.6f",transform);

I use String.format to force the value to be shown with 6 decimals and not with E.

But when transform equals to 0.040000 I want to have 0.04 as result. And for 0.000006 I want to have 0.000006.

Upvotes: 2

Views: 231

Answers (1)

tundundun
tundundun

Reputation: 644

Use NumberFormat instead of String.format():

NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(6);
nf.format(yourNumber);

Upvotes: 2

Related Questions