• Post Reply Bookmark Topic Watch Topic
  • New Topic

Converting a double value in scientific notation  RSS feed

 
Daniel McDade
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm retrieving a value from a backend service that is of data type double, but it is returning the value in scientific notation format (1.383739E8, for example).

How can I take that, and convert it to its actual whole value? Is there some sort of formatter? If so, how do I use it? Thanks for any help!

dannymac21
 
Ramen Chatterjee
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Not tried t myself but I think you could try java.text.DecimalFormat.parse(String).

Regards

Ramen
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Daniel.

You can always cast the number. A parser ought to be able to read E formats. I tried it:-Output:
Please enter numbers, using 0 to finish:- 123
Last number: 123. Enter another, 0 to finish: 123.45e6
Last number: 123450000. Enter another, 0 to finish: 123.45e11
Last number: 2147483647. Enter another, 0 to finish: 0
Last number: 0. Enter another, 0 to finish:
Note you have to make sure your double numbers are within the range of int numbers, as you see from above.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!