• 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

Conversion of Number datatype in Oracle to Double format or a String.

 
Ranch Hand
Posts: 51
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am having a column in table named amountClaimed[Number(20,2)].
I have a value in that column 8787854545.89 and I want to print it on the screen exactly in the same way.
But what I am getting is 8.78785454589E9.
I am using rs.getDouble method and trying it to display it through variable in double.
the code is like:

Thanks in advance....
 
Sheriff
Posts: 7134
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's the way how large double values look like when they converted to String. If you really need to print on System.out, you may use something like:
System.out.printf("%.2f",temp);
Which prints the double value with only two digits in the decimal place. If you need to get a String value out of it, try using String.format(-) method.

Not related to JSP. Moving to BJ.
 
Vivek Kr Agrawal
Ranch Hand
Posts: 51
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for replying back.
I also have to compare some values which are in "Double". Can you give some suggestions?
 
Devaka Cooray
Sheriff
Posts: 7134
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Compare? If you need to check if the double values d1 and d2 are equivalent, that's what == operator is for.
 
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
Can't you use rs.getString(3) or rs.getBigDecimal(3)?
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Devaka Cooray wrote:Compare? If you need to check if the double values d1 and d2 are equivalent, that's what == operator is for.



There are a couple of things to note however:

1. We generally don't simply compare floating point types for equality using simply d1 == d2. Because of the errors inherent in floating point calculations, we need to compare whether d1 and d2 differ by less than some epsilon.

2. The OP mentioned Double with a capital D. I don't know if that was a typo or deliberate. If we're dealing with Double objects (as opposed to double primitives), we definitely don't want to use == .
 
I'm all tasted up for a BLT! This tiny ad wants a monte cristo!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic