Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

java.math.BigDecimal - help needed with maths

2,366 views
Skip to first unread message

bob brown

unread,
Dec 30, 2002, 4:46:35 AM12/30/02
to
Hi,

When I tried to run the following code, error occurred.
ERROR - operator * cannot be applied to java.math.BigDecimal
operator + cannot be applied to java.math.BigDecimal

Code:
java.math.BigDecimal A = new java.math.BigDecimal(0.1);
java.math.BigDecimal B = new java.math.BigDecima(100);
java.math.BigDecimal C = A * B;
java.math.BigDecimal D = B + C;

Isn't it too restrictive if we cannot even use operators in BigDecimal?

Can you help?
BoB

Leon

unread,
Dec 30, 2002, 6:32:31 AM12/30/02
to

"bob brown" <bob...@start.com.au> schreef in bericht
news:afe84a4.02123...@posting.google.com...

Maybe next time, first have a look at the class documentation
for BigDecimal.... it has operations like add(), subtract(),
etc. that will do this for you.
http://java.sun.com/j2se/1.4.1/docs/api/java/math/BigDecimal.html

And besides, you knew that java doesn't support operator
overloading, right? ;)

Cheers,
Leon.

Frank Breuer

unread,
Dec 30, 2002, 7:13:55 AM12/30/02
to
"bob brown" wrote:

> Isn't it too restrictive if we cannot even use operators in
> BigDecimal?

There is no operator overloading in Java. End of discussion.

> Can you help?

Read the API documentation of BigDecimal.

Jim Sculley

unread,
Dec 30, 2002, 10:00:17 AM12/30/02
to
Frank Breuer wrote:
> "bob brown" wrote:
>
>
>>Isn't it too restrictive if we cannot even use operators in
>>BigDecimal?
>
>
> There is no operator overloading in Java. End of discussion.

Except of course for String concatenation.

Jim S.
--
Remove my extraneous mandibular appendages to reply via e-mail.

Lee Fesperman

unread,
Dec 31, 2002, 1:54:23 AM12/31/02
to
Jim Sculley wrote:
>
> Frank Breuer wrote:
> > "bob brown" wrote:
> >
> >
> >>Isn't it too restrictive if we cannot even use operators in
> >>BigDecimal?
> >
> >
> > There is no operator overloading in Java. End of discussion.
>
> Except of course for String concatenation.

+, -, * and / are overloaded for int, long, float, double.

--
Lee Fesperman, FirstSQL, Inc. (http://www.firstsql.com)
==============================================================
* The Ultimate DBMS is here!
* FirstSQL/J Object/Relational DBMS (http://www.firstsql.com)

Jim Sculley

unread,
Dec 31, 2002, 10:55:44 AM12/31/02
to
Lee Fesperman wrote:
> Jim Sculley wrote:
>
>>Frank Breuer wrote:
>>
>>>"bob brown" wrote:
>>>
>>>
>>>
>>>>Isn't it too restrictive if we cannot even use operators in
>>>>BigDecimal?
>>>
>>>
>>>There is no operator overloading in Java. End of discussion.
>>
>>Except of course for String concatenation.
>
>
> +, -, * and / are overloaded for int, long, float, double.

Yes, but those 'stick out' a little less than Strings.

Eric Sosman

unread,
Jan 2, 2003, 5:46:31 PM1/2/03
to
Jim Sculley wrote:
>
> Lee Fesperman wrote:
> > Jim Sculley wrote:
> >
> >>Frank Breuer wrote:
> >>
> >>>"bob brown" wrote:
> >>>
> >>>
> >>>
> >>>>Isn't it too restrictive if we cannot even use operators in
> >>>>BigDecimal?
> >>>
> >>>
> >>>There is no operator overloading in Java. End of discussion.
> >>
> >>Except of course for String concatenation.
> >
> >
> > +, -, * and / are overloaded for int, long, float, double.
>
> Yes, but those 'stick out' a little less than Strings.

... and then there are the shift operators, the
assignment operator, the equality and relational
operators, the dot operator (if the governing documents
define dot as an operator; I'm not a language lawyer),
and the most overloaded and overloadable operator of
them all: `instanceof'.

IMHO, tagging all these with the term "overloading"
is overloading the terminology.

--
Eric....@sun.com

0 new messages