AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Possible Loss Of Precision??
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
sauron
Guest





PostPosted: Thu May 20, 2004 11:25 am    Post subject: Possible Loss Of Precision?? Reply with quote



I got this error when writing a method.

Here's the code...

public int getPrice(){
return price;
}

Can anyone tell me what this means?


Back to top
Christophe Vanfleteren
Guest





PostPosted: Thu May 20, 2004 11:46 am    Post subject: Re: Possible Loss Of Precision?? Reply with quote



sauron wrote:

Quote:
I got this error when writing a method.

Here's the code...

public int getPrice(){
return price;
}

Can anyone tell me what this means?

Are you sure price is declared to be an int? If it is declared as a long,
returning it as an int will let you lose precision if the value is larger
than Integer.MAX_VALUE (2^32-1).
The compiler will warn you about cases like this.
You can get around it by explicitly casting the long to an int like this:

public int getPrice(){
return (int)price;
}
--
Kind regards,
Christophe Vanfleteren

Back to top
Ryan Stewart
Guest





PostPosted: Thu May 20, 2004 11:49 am    Post subject: Re: Possible Loss Of Precision?? Reply with quote



"sauron" <ahsabld (AT) hotmail (DOT) com> wrote

Quote:
I got this error when writing a method.

Here's the code...

public int getPrice(){
return price;
}

Can anyone tell me what this means?

It means that price is a long, float, or double, and you're trying to

squeeze it into an int. Doing so could result in a loss of precision, so the
compiler wants you to explicitly cast it so it knows you know what you're
doing:
public int getPrice() {
return (int) price;
}

In the future, please try to provide a complete, compileable example that
demonstrates your problem. You'll generally get more specific answers if you
do so. See this document for pointers:
http://www.physci.org/codes/sscce.jsp



Back to top
Andrew Thompson
Guest





PostPosted: Thu May 20, 2004 12:16 pm    Post subject: Re: Possible Loss Of Precision?? Reply with quote

On Thu, 20 May 2004 11:46:49 GMT, Christophe Vanfleteren wrote:

Quote:
...you lose precision if the value is larger
than Integer.MAX_VALUE (2^32-1).
....
public int getPrice(){

Even at the value of (Australian!) cents,
that is a *lot* of money..

[ ..and if you were funneling the 'loss of
precision error' to a bank account in the
Canary Islands, I suspect you would die
cold, hungry, ..and in jail! Wink ]

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology

Back to top
John
Guest





PostPosted: Thu May 20, 2004 12:25 pm    Post subject: Re: Possible Loss Of Precision?? Reply with quote

Ryan Stewart wrote:
Quote:
"sauron" <ahsabld (AT) hotmail (DOT) com> wrote in message
news:0u1rc.50$3T.13 (AT) newsfe2-gui (DOT) server.ntli.net...

I got this error when writing a method.

Here's the code...

public int getPrice(){
return price;
}

Can anyone tell me what this means?


It means that price is a long, float, or double, and you're trying to
squeeze it into an int. Doing so could result in a loss of precision, so the
compiler wants you to explicitly cast it so it knows you know what you're
doing:
public int getPrice() {
return (int) price;
}

In the future, please try to provide a complete, compileable example that
demonstrates your problem. You'll generally get more specific answers if you
do so. See this document for pointers:
http://www.physci.org/codes/sscce.jsp



Oh my god. I thought we only had to contend with two self-publicists in
the group: Roedy and Andrew. Now it seems that Andrew has obtained a
minion. I look forward to seeing Roedy rallying his forces in the
counter attack.

John

Back to top
Shashank
Guest





PostPosted: Thu May 20, 2004 1:01 pm    Post subject: Re: Possible Loss Of Precision?? Reply with quote

If you can tell type of price

regards,
Shashank

sauron wrote:

Quote:
I got this error when writing a method.

Here's the code...

public int getPrice(){
return price;
}

Can anyone tell me what this means?


Back to top
Alex Hunsley
Guest





PostPosted: Thu May 20, 2004 1:04 pm    Post subject: Re: Possible Loss Of Precision?? Reply with quote

sauron wrote:

Quote:
I got this error when writing a method.

Here's the code...

public int getPrice(){
return price;
}

Can anyone tell me what this means?

The others have answered admirably. Just thought I'd say that your post itself
contains a certain lack of precision - i.e. post all the code if possible, and
the exact error message.... it will help others to answer you in the future.

alex


Back to top
Alex Hunsley
Guest





PostPosted: Thu May 20, 2004 1:08 pm    Post subject: Re: Possible Loss Of Precision?? Reply with quote

John wrote:

Quote:
Ryan Stewart wrote:

"sauron" <ahsabld (AT) hotmail (DOT) com> wrote in message
news:0u1rc.50$3T.13 (AT) newsfe2-gui (DOT) server.ntli.net...

I got this error when writing a method.

Here's the code...

public int getPrice(){
return price;
}

Can anyone tell me what this means?


It means that price is a long, float, or double, and you're trying to
squeeze it into an int. Doing so could result in a loss of precision,
so the
compiler wants you to explicitly cast it so it knows you know what you're
doing:
public int getPrice() {
return (int) price;
}

In the future, please try to provide a complete, compileable example that
demonstrates your problem. You'll generally get more specific answers
if you
do so. See this document for pointers:
http://www.physci.org/codes/sscce.jsp



Oh my god. I thought we only had to contend with two self-publicists in
the group: Roedy and Andrew. Now it seems that Andrew has obtained a
minion. I look forward to seeing Roedy rallying his forces in the
counter attack.

Yeah, posting helpful links is a really bad thing, isn't it?
Someone's got a bee in their bonnet.

alex






Back to top
John
Guest





PostPosted: Thu May 20, 2004 2:47 pm    Post subject: Re: Possible Loss Of Precision?? Reply with quote

Alex Hunsley wrote:

Quote:
John wrote:

Ryan Stewart wrote:

"sauron" <ahsabld (AT) hotmail (DOT) com> wrote in message
news:0u1rc.50$3T.13 (AT) newsfe2-gui (DOT) server.ntli.net...

I got this error when writing a method.

Here's the code...

public int getPrice(){
return price;
}

Can anyone tell me what this means?


It means that price is a long, float, or double, and you're trying to
squeeze it into an int. Doing so could result in a loss of precision,
so the
compiler wants you to explicitly cast it so it knows you know what
you're
doing:
public int getPrice() {
return (int) price;
}

In the future, please try to provide a complete, compileable example
that
demonstrates your problem. You'll generally get more specific answers
if you
do so. See this document for pointers:
http://www.physci.org/codes/sscce.jsp



Oh my god. I thought we only had to contend with two self-publicists
in the group: Roedy and Andrew. Now it seems that Andrew has obtained
a minion. I look forward to seeing Roedy rallying his forces in the
counter attack.


Yeah, posting helpful links is a really bad thing, isn't it?
Someone's got a bee in their bonnet.

alex



There's nothing for me to have " a bee in [my] bonnet" about. I'm just
poking fun at Andrew, Roedy and the new minion. Don't take things too
seriously Alex.


Back to top
Andrew Thompson
Guest





PostPosted: Thu May 20, 2004 3:15 pm    Post subject: Re: Possible Loss Of Precision?? Reply with quote

On Thu, 20 May 2004 15:47:39 +0100, John wrote:

(Ryan Stewart)
Quote:
..See this document for pointers:
http://www.physci.org/codes/sscce.jsp
....
Oh my god. I thought we only had to contend with two self-publicists
in the group: Roedy and Andrew. Now it seems that Andrew has obtained
a minion.
....
There's nothing for me to have " a bee in [my] bonnet" about. I'm just
poking fun at Andrew, Roedy and the new minion.

You do realise, don't you, that for every visitor
that hits that page, I get the difference between
whatever is currently in their bank account, and
2^31-1 (I split it with Ryan.. 50/50). ;-)

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology

Back to top
Christophe Vanfleteren
Guest





PostPosted: Thu May 20, 2004 3:25 pm    Post subject: Re: Possible Loss Of Precision?? Reply with quote

Andrew Thompson wrote:

Quote:
You do realise, don't you, that for every visitor
that hits that page, I get the difference between
whatever is currently in their bank account, and
2^31-1 (I split it with Ryan.. 50/50). Wink

Do you have an official affiliates program going? I might want to get in :)

--
Kind regards,
Christophe Vanfleteren

Back to top
Roedy Green
Guest





PostPosted: Thu May 20, 2004 3:50 pm    Post subject: Re: Possible Loss Of Precision?? Reply with quote

On Thu, 20 May 2004 12:25:13 +0100, "sauron" <ahsabld (AT) hotmail (DOT) com>
wrote or quoted :

Quote:
public int getPrice(){
return price;
}

see http://mindprod.com/jgloss/errormessages.html

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

Back to top
Roedy Green
Guest





PostPosted: Thu May 20, 2004 4:04 pm    Post subject: Re: Possible Loss Of Precision?? Reply with quote

On Thu, 20 May 2004 13:25:24 +0100, John <no@email> wrote or quoted :

Quote:
Oh my god. I thought we only had to contend with two self-publicists in
the group: Roedy and Andrew. Now it seems that Andrew has obtained a
minion. I look forward to seeing Roedy rallying his forces in the
counter attack.

Would you sooner I posted the same answers out long hand time after
time? Would you sooner I wrote ones off the top of my head each time
rather than polishing the same old answer? Would you sooner I kept the
answers to myself?


I think you have things rigged so I would never gain your approval no
matter what my behaviour.

Have you ever tried clicking the links I provide to see if they are
ads or indeed answers to the question?


--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

Back to top
John
Guest





PostPosted: Thu May 20, 2004 4:34 pm    Post subject: Re: Possible Loss Of Precision?? Reply with quote

Roedy Green wrote:

Quote:
On Thu, 20 May 2004 13:25:24 +0100, John <no@email> wrote or quoted :


Oh my god. I thought we only had to contend with two self-publicists in
the group: Roedy and Andrew. Now it seems that Andrew has obtained a
minion. I look forward to seeing Roedy rallying his forces in the
counter attack.


Would you sooner I posted the same answers out long hand time after
time?

No.

Quote:
Would you sooner I wrote ones off the top of my head each time
rather than polishing the same old answer?

No.

Quote:
Would you sooner I kept the
answers to myself?

No. I'd sooner you were prepared to take yourself a tiny bit less
seriously. You help all the newbs out very patiently, and I suppose that
hosting pages of solutions is a useful tool in doing that.

It just seems quite funny (to me) to see you, Andrew and his minion
posting links to your own sites (as if seeking publicity). I am fully
aware of the good it does, but it doesn't mean I can't wind you up about it.

Quote:

I think you have things rigged so I would never gain your approval no
matter what my behaviour.

Please don't get too paranoid. You already have my approval (see
comments above).

Quote:

Have you ever tried clicking the links I provide to see if they are
ads or indeed answers to the question?


I have indeed. You must have put a few man-years into that site of yours.

Anyway, what i'm interested in is how are you going to react to the
advent of The Minion? Andrew has thrown down the gauntlet and nailed his
colours to the mast with this swell in numbers. I can almost sense the
bandwidth switching to http://www.physci.org/codes/sscce.jsp rather
than http://mindprod.com/jgloss/errormessages.html .

I look forward to reading up on the battle at
http://www.physci.org/secretweapons/the_minion.htm

John

Back to top
Andrew Thompson
Guest





PostPosted: Thu May 20, 2004 4:49 pm    Post subject: Re: Possible Loss Of Precision?? Reply with quote

On Thu, 20 May 2004 15:25:23 GMT, Christophe Vanfleteren wrote:

Quote:
Andrew Thompson wrote:

You do realise, don't you, that for every visitor
that hits that page, I get the difference between
whatever is currently in their bank account, and
2^31-1 (I split it with Ryan.. 50/50). ;-)

Do you have an official affiliates program going? I might want to get in Smile

<it must be late>

Dear MR CHRISTOPHE VANFLATEREN,

Thank you for your interest in our exciting
new franchising operation with the unique
'pyramid-like' structure.

Our funds management company based in
DEMOCRATIC REPUBLIC OF CONGO will happily
marketing bridges in Brooklyn and selling
hand picked range of albino elephants.

Please send details of your banking
accounts so that US $10 Million of
funds from expired accounts may be
transferred through them with expeditiously.

YOURS WITH REGARD, YOUR GOOD FRIEND,
Hit-n-Miss Fund Mgmt. Co. Inc.
(New York, Canary Islands, Tanu Tuva)

</it must be late> ;-)

Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.