This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes BigDecimal issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "BigDecimal issue" Watch "BigDecimal issue" New topic
Author

BigDecimal issue

Hd Desai
Ranch Hand

Joined: Aug 04, 2003
Posts: 65
Hi,

What is the difference between BigDecimal bd = new BigDecimal (1) and BigDecimal bd = new BigDecimal("1") ? We are using java 1.4

Please let me know about the same.

Thank you in advance.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Hd Desai wrote:Hi,

What is the difference between BigDecimal bd = new BigDecimal (1) and BigDecimal bd = new BigDecimal("1")


What do the docs tell you?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37950
    
  22
You probably won’t find much difference. But try. . . and (I hope) there will be a difference.
Hd Desai
Ranch Hand

Joined: Aug 04, 2003
Posts: 65
Thank you for response Jeff.

I went through the docs before posting here..Was not able to get clear answer. BigDecimal = new BigDecimal("1") creates new object with 1 as string...while BigDecimal = new BigDecimal(1) is as BigInteger...but in any case it should work. But this program is failing.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37950
    
  22
Good grief! I have, more by luck than good management, hit on the same values they quote in the API documentation!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37950
    
  22
Are you using whole numbers throughout?
Hd Desai
Ranch Hand

Joined: Aug 04, 2003
Posts: 65
thank you Ritchie.

no it is not whole number. it is number with 6 scale ..

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37950
    
  22
Did you try my little example? Did you read the constructor documentation? I would have thought those would be very helpful.

And always tell us what is going wrong.
Hd Desai
Ranch Hand

Joined: Aug 04, 2003
Posts: 65
thanks again Ritchie...yes I read whole doc..and it was my mistake i was reading 1.5 javadoc...

BigDecimal constructor does not take int till 1.5 . Now got it all.

Thank you very much once again...
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11153
    
  16

Hd Desai wrote:But this program is failing.

just as a tip for next time...just saying "my program doesn't work" is really pointless. There are thousands of ways it could "not work". One of three things should be happening:

1) You get a compiler error. If so, tell us the EXACT text of that error. There is a LOT of info there, once you learn how to read it
2) Your program crashes when it runs. Again, you'll get some kind of message telling you what went wrong.
3) Your program runs, but behaves differently than you expect. We don't know what you expect, nor do we know what it does do. You need to tell us both.

You will find you generally get much more help, better help, and quicker help, if you do the above.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Hd Desai wrote:Thank you for response Jeff.

I went through the docs before posting here..Was not able to get clear answer. BigDecimal = new BigDecimal("1") creates new object with 1 as string...while BigDecimal = new BigDecimal(1) is as BigInteger


It says a lot more than that. You probably ought to read it, very closely. And a little bit of thinking and effort would have led you to try something like this:




...but in any case it should work. But this program is failing.


Saying it "should work" is meaningless. It's doing exactly what it should do. The problem is that you have erroneous assumptions about how a given bit of code "should" behave.

And note that ItDoesntWorkIsUseless.(⇐click) You need to TellTheDetails(⇐click) so that people here will understand exactly what is going wrong.
Hd Desai
Ranch Hand

Joined: Aug 04, 2003
Posts: 65
Thank you Fred for point int out and I completely agree with you on this. Will take care next time.

Thank you for your time and effort.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37950
    
  22
Hd Desai wrote:thanks again Ritchie...yes I read whole doc..and it was my mistake i was reading 1.5 javadoc...

BigDecimal constructor does not take int till 1.5 . . . .
What has an int got to do with it? You said earlier you were not using whole numbers throughout. So some of your code uses the BigDecimal(int) constructor and the rest the BigDecimal(double) constructor? As Jeff has said, we need to know the correct details before we can help.
 
 
subject: BigDecimal issue
 
Similar Threads
Class cast on Object Array
BigDecimal rounding problem
how to check whether BigDecimal or String is whole number or not ?
Trouble with double primitive type
how to access an IN OUT parameter ?