how to retrieve a number with more dec places

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

how to retrieve a number with more dec places

Bob M
Hi

I have a derby database with records that contain a price e.g. 1.21098

I retrieve it by the following line

price = rs.getDouble("price");

when I print it out I get :- 1.21

What do I need to change so that I retrieve the full price with all its decimal places?

Bob M
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to retrieve a number with more dec places

kristwaa
Hi Bob,

Assuming you have stored it correctly, have you tried using getBigDecimal?


--
Kristian


Den tir. 28. feb. 2017, 07:03 skrev Bob M <[hidden email]>:
Hi

I have a derby database with records that contain a price e.g. 1.21098

I retrieve it by the following line

price = rs.getDouble("price");

when I print it out I get :- 1.21

What do I need to change so that I retrieve the full price with all its
decimal places?

Bob M



--
View this message in context: http://apache-database.10148.n7.nabble.com/how-to-retrieve-a-number-with-more-dec-places-tp147257.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to retrieve a number with more dec places

Bob M
Hi

I haven't tried BigDecimal

To do that, what do you change the following to..............

private double price = 0;

Bob M
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to retrieve a number with more dec places

John English-3
In reply to this post by Bob M
On 28/02/2017 08:03, Bob M wrote:
> Hi
>
> I have a derby database with records that contain a price e.g. 1.21098
>
> I retrieve it by the following line
>
> price = rs.getDouble("price");
>
> when I print it out I get :- 1.21

How are you printing it out? The problem is probably there, not with the
data you've read -- is your print routine printing it rounded to two
decimal places?
--
John English
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to retrieve a number with more dec places

Bob M
Hi John

I write the price out to a file

I wish to do simple maths e.g. subtracting one price from a second price and I need to be using all dec. places

At the moment my subtraction often results in zero because of the curtailed prices

When I view my Apachy table using Netbeans IDE I see the prices with 4 or 5 dec. places

Bob M
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to retrieve a number with more dec places

Bob M
In reply to this post by Bob M
Hi everybody

My apologies................(very red face)

The prices I was saving in my table were only to 3 decimals

My bad :(

Bob M
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to retrieve a number with more dec places

John English-3
In reply to this post by Bob M
On 28/02/2017 10:58, Bob M wrote:
> I write the price out to a file

So you said, but *how* do you write it out to a file? What does your
code look like? Are you for example using printf with a "%.2f" format
specification, which would round the written-out value to 2 d.p.s?

--
John English
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to retrieve a number with more dec places

John English-3
In reply to this post by Bob M
On 01/03/2017 00:14, Bob M wrote:
> The prices I was saving in my table were only to 3 decimals

OK, just saw this after replying to your previous post.

There's usually a simple explanation when things like this happen... :)

--
John English
Loading...