2

In my application, I allowed user to input DOUBLE value (2 decimal places) then total up and display. It works fine with value lesser than 10,000,000; However, when displaying

Double totalvalue = 1000000000.50;
Displayed as 1.0E9
Intent to get Display as : 1000000000.50

Double totalvalue = 10000000.00
Displayed as 1.0E7
Intent to get Display as : 10000000.00

So my problem is how to get Display the actual value? p/s: I did research on this issues for few hours but unfortunately I doesn't get any answer for that.

4
  • @boxed__l No, it won't work with "Double.toString()" Commented Aug 9, 2013 at 16:58
  • @LoganMurphy The question you reference is about display as an integer, and many of the answers, including the accepted one, would not work for this case. Commented Aug 9, 2013 at 17:06
  • ya, toString will simply convert the value as string without changing the format. I applied the solution given and it works fine. BTW Thanks all. Commented Aug 9, 2013 at 17:09
  • @PatriciaShanahan The second answer has a solution Commented Aug 9, 2013 at 17:11

2 Answers 2

3

You can use this:

String.format("%1$.2f", totalvalue);

to format your Double without the E notation.

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

3 Comments

Is it significantly different from "%.2f"?
@SajalDutta - When there's only one argument to the format, there's no difference at all. I just have a habit of always specifying the position for each format conversion. I see we have identical answers. I started writing my answer, I think, while you were editing your earlier deleted answer, which was considerably different. So +1 to you. :)
@TedHopp lol.. I really wanted to know aside from multiple arguments with index specifiers if there was any other stuff that I didn't know of. Nothing to do with our answers. Thanks. +1 to you too. :)
2

You can display as-

String.format("%.2f", totalValue)

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.