1

I have a bean which has a property of type double. When I pass this bean to view layer, it shows the value in scientific notation For example: 9.78313E+10 instead of 97831300000.

I want the result without scientific notation and I cannot change the data type of that field. Please let me know if there is any workaround.

GhostCat
  • 137,827
  • 25
  • 176
  • 248
Sunny
  • 91
  • 1
  • 13
  • Seems you want to format this double value: http://stackoverflow.com/questions/12806278/double-decimal-formatting-in-java – peter.petrov Mar 25 '15 at 08:54

2 Answers2

3

You can use the printf() with %f:

System.out.printf("%.0f", value);

Here you can find a beautiful printf format cheat sheet by Alvin Alexander that might help you (and hopefully others) a lot.

abarisone
  • 3,707
  • 11
  • 35
  • 54
0

How the number is shown depends on the formatting that is used by the component showing the value. If you can't access that code to use a different formater; then there is nothing you can do.

See https://docs.oracle.com/javase/tutorial/java/data/numberformat.html for starters.

One option might be: can you exchange the bean implementation; so instead of providing a "double" number; can you change it to provide a string (in that case, you could control the formatting of the number).

GhostCat
  • 137,827
  • 25
  • 176
  • 248