You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Bob M <rg...@orcon.net.nz> on 2017/02/28 06:03:34 UTC

how to retrieve a number with more dec places

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.

Re: how to retrieve a number with more dec places

Posted by John English <jo...@gmail.com>.
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

Re: how to retrieve a number with more dec places

Posted by Bob M <rg...@orcon.net.nz>.
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



--
View this message in context: http://apache-database.10148.n7.nabble.com/how-to-retrieve-a-number-with-more-dec-places-tp147257p147261.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.

Re: how to retrieve a number with more dec places

Posted by John English <jo...@gmail.com>.
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

Re: how to retrieve a number with more dec places

Posted by Bob M <rg...@orcon.net.nz>.
Hi

I haven't tried BigDecimal

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

private double price = 0;

Bob M



--
View this message in context: http://apache-database.10148.n7.nabble.com/how-to-retrieve-a-number-with-more-dec-places-tp147257p147259.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.

Re: how to retrieve a number with more dec places

Posted by Kristian Waagan <kr...@apache.org>.
Hi Bob,

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


-- 
Kristian

Den tir. 28. feb. 2017, 07:03 skrev Bob M <rg...@orcon.net.nz>:

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.

Re: how to retrieve a number with more dec places

Posted by John English <jo...@gmail.com>.
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

Re: how to retrieve a number with more dec places

Posted by Bob M <rg...@orcon.net.nz>.
Hi everybody

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

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

My bad :(

Bob M



--
View this message in context: http://apache-database.10148.n7.nabble.com/how-to-retrieve-a-number-with-more-dec-places-tp147257p147264.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.