• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Please help! How do you expend scientific notation?

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a string that comes in the format similar to this "0E-8". I have no control what format this string comes in. I have to expend this string into a string of "0.00000000". This is for a financial application so the exact length of the string is important. Does anyone know of a way how? Thanks!
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are working with currencies, forget all about float and double and use java.math.BigDecimal instead.
 
Yar lag
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the help, but like I said, I don't have a choice as to how I receive the input. The input is a string, in scientic notation format. I need to convert this string into another string. That is my task. Any help?
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sorry I couldn't help you. Please try java.math.BigDecimal instead.

Ok, I'm joking a bit, but that class can really help you. Check out the toXXXString() methods.
 
Yar lag
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see how BigDecimal can help with this at all, have you read my requirements?
 
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have no control over what it comes in as, but once you recieve it can you change to whatever you want, do your calculations/whatever you are doing, change it back, then do whatever you want to it?
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, Rob has read your requirements. One of them was that the application must handle money, in which case BigDecimal is essential.
You can pass such a number (as a String, of course) to the BigDecimal constructor, and you can specify number of decimal places.

You may mean you want particular formatting when you display the number. That is different; you would use DecimalFormat or similar but, since Java5, I think the formatting capabilities of Formatter make it a better choice.
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You must have missed BigDecimal's toPlainString() method. I tried it before my previous post, and it did exactly what you want: show 0.00000000.
reply
    Bookmark Topic Watch Topic
  • New Topic