0

i have got such part of the code:

double double1 = 0.000112344;
String string1 = "0.000112344";
System.out.println(String.valueOf(double1) + " : "+string1);

results:

1.12344E-4 : 0.000112344

The question is, how can i parse double1 to string that will show me 0.000112344?

3
  • 6
    Use NumberFormat: stackoverflow.com/questions/15649833/java-numberformat Commented Jul 18, 2013 at 13:41
  • Thanks, working great :) Commented Jul 18, 2013 at 13:46
  • In general, "parsing" refers to converting a string to some other representation. The opposite is often called "formatting" or sometimes "unparsing". Commented Jul 18, 2013 at 17:34

1 Answer 1

2
double double1 = 0.000112344;
String string1 = "0.000112344";
System.out.printf("%.9f: %s%n", double1, string1);
0.000112344: 0.000112344

In general, String.format("%.nf", double1) will produce a string representation of double1 rounded to n decimal places.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.