File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Vivek Kr Agrawal
Ranch Hand
Posts: 51
Eclipse IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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....
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4116
195
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • 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 Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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
ExamLab Creator
Marshal
Pie
Posts: 4116
195
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can't you use rs.getString(3) or rs.getBigDecimal(3)?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • 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 == .
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic