0

I'm pretty new to Java and I am currently working on a project where I need to work with Floating points.

I am trying to convert the value from 3.5E8 (Double value) to a string value of 350000000. I have looked on the internet but currently I can't find a solution.

4
  • 1
    Look at DecimalFormat. Commented Jun 13, 2013 at 12:29
  • System.out.println(new BigDecimal(f).toPlainString()); ? Commented Jun 13, 2013 at 12:30
  • way2java.com/string-and-stringbuffer/… + many other conversion/casting examples. Recomend to book Commented Jun 13, 2013 at 12:34
  • Although the answers so far will work for 3.5E8, they may not do what you want for some other inputs. You need to consider the range of inputs before selecting a solution. Commented Jun 13, 2013 at 12:39

3 Answers 3

5

Use:

new BigDecimal(yourValue).toPlainString();
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect, just what I wanted. Thank you.
2

try String.format

String str = String.format("%.0f",3.5E8);

or

String str = new DecimalFormat("#.#").format(3.5E8);

Comments

1

You can use the BigDecimal class , toPlainString() method :

Returns a string representation of this BigDecimal without an exponent field.

 System.out.println(new BigDecimal(doubleValue).toPlainString());

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.