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
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.
> 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.
Except of course for String concatenation.
Jim S.
--
Remove my extraneous mandibular appendages to reply via e-mail.
+, -, * 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)
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.