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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
BlackHat
  • 147
  • 2
  • 3
  • 13

2 Answers2

3

You can use this:

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

to format your Double without the E notation.

Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
  • Is it significantly different from "%.2f"? – Sajal Dutta Aug 09 '13 at 17:02
  • @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. :) – Ted Hopp Aug 09 '13 at 17:09
  • @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. :) – Sajal Dutta Aug 09 '13 at 17:17
2

You can display as-

String.format("%.2f", totalValue)
Sajal Dutta
  • 18,272
  • 11
  • 52
  • 74