aspose file tools*
The moose likes JDBC and the fly likes Retriving data with four decimal places Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Retriving data with four decimal places" Watch "Retriving data with four decimal places" New topic
Author

Retriving data with four decimal places

Ajith George
Ranch Hand

Joined: Dec 22, 2005
Posts: 109
i have a problem in retriving data with four decimal places from database.
I was using rs.getDouble() method. But this gives me only 2 decimal places on the result. Which is the best method to be used to retrive 4 decimal places. Thanks in advance.


SCJP 1.4, Brainbench
LinkedIn - Blog
Eduardo Dela Rosa
Greenhorn

Joined: Apr 15, 2004
Posts: 25
Hi Ajith,

Firstly, the thing that can affect your output may be one or combination of the following:

  • the JDBC driver itself that you are using, i.e., MySQL, PostgreSQL, Cloudscape, etc.
  • Or the number of decimal places defined in your table


  • If your column is defined to have two (2) decimal places, say , then no matter what value you get - you'll always get N.NN.

    Likewise, if your column is defined to have four decimal places, say , then no matter what value you get - you'll always get N.NNNN.

    But somehow, if you use , then you'll be able to get a value in N.NNNN, no matter how many decimal places you've defined in your column.

    You may consider the following code for illustration (although there might be some other best solution for your case):


    Originally posted by Ajith George:
    I was using rs.getDouble() method. But this gives me only 2 decimal places on the result. Which is the best method to be used to retrive 4 decimal places. Thanks in advance.

    [ March 29, 2006: Message edited by: Eduardo Dela Rosa ]
    [ March 29, 2006: Message edited by: Eduardo Dela Rosa ]

    Eduardo dela Rosa<br />SCJP 1.4
    Ajith George
    Ranch Hand

    Joined: Dec 22, 2005
    Posts: 109
    Thanks for your reply. I think this will solve my problem.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Retriving data with four decimal places