This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Conversion of Number datatype in Oracle to Double format or a String. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Conversion of Number datatype in Oracle to Double format or a String." Watch "Conversion of Number datatype in Oracle to Double format or a String." New topic
Author

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

Vivek Kr Agrawal
Ranch Hand

Joined: Sep 08, 2012
Posts: 51

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....


Vivek Agrawal
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3019
    
  35

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.


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Vivek Kr Agrawal
Ranch Hand

Joined: Sep 08, 2012
Posts: 51

Thanks for replying back.
I also have to compare some values which are in "Double". Can you give some suggestions?
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3019
    
  35

Compare? If you need to check if the double values d1 and d2 are equivalent, that's what == operator is for.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

Can't you use rs.getString(3) or rs.getBigDecimal(3)?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

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 agree. Here's the link: http://aspose.com/file-tools
 
subject: Conversion of Number datatype in Oracle to Double format or a String.
 
Similar Threads
using jstl formatNumber with rs.getString
ClassNotFoundException with ResourceBundle
NumberFormatException
While loops
how Can I fix this problem