- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
How to initialize a BigDecimal field
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
03-20-2012 08:39 AM
Hi,
Suppose transactionAmount is a defined as a BigDecimal in the JAVA OM, how to initialize it and give it a default value.
Following code gives the error as shown below.
transactionAmount = 100.00;
Error: Explicit cast required to assign a 'real' to a 'BigDecimal' use 'as a BigDecimal'.
Kindly advise.
Thanks
Shubham
PayPal, Inc.
Solved! Go to Solution.
Re: How to initialize a BigDecimal field
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Not the Solution
- Email to a Friend
- Report Inappropriate Content
03-21-2012 07:49 AM
the error is telling you the solution.
transactionAmount = 100.00 as a BigDecimal.
does this give you an error?
Re: How to initialize a BigDecimal field
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Not the Solution
- Email to a Friend
- Report Inappropriate Content
03-21-2012 09:27 AM
Thanks for your reply.
I have tried that as well. It complies fine but when I print the value out, the value is not passed correctly.
Code
print("transactionAmount":transactionAmount).
Output
transactionAmount:bigdecimal#1
I am guessing that because BigDecimal is a class, I may need a different type of declaration and assignmet.
Thanks
Shubham
PayPal, Inc.
Re: How to initialize a BigDecimal field
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Not the Solution
- Email to a Friend
- Report Inappropriate Content
03-22-2012 03:31 PM
What you see is the default representation of an object instance in Blaze Advisor. A BigDecimal instance is (at least in your case) not treated as a primitive, and is therefore represented by the instance "id" in Blaze.
If you would like to print the value represented by the BigDecimal instance, try one of the following: ("theValue" contains a reference to a BigDecimal instance)
For monetary values:
asMoney is some money initially theValue as a money;
print("value: " asMoney);
For decimal values (and you are not concerned about the possible loss of precision):
asReal is some real initially theValue as a real;
print("value: " asReal);
For integer values (still not concerned about precision etc..):
asInteger is some integer initially theValue as an integer;
print("value: " asInteger);
Please note that you can do the cast inside the print(), it is separated here for readability. Also please note that I didn't test these lines of code right now, but they should work.
Regards,
Jostein
Re: How to initialize a BigDecimal field
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Not the Solution
- Email to a Friend
- Report Inappropriate Content
03-28-2012 10:01 AM
Hi Jostein,
Thanks for the explanation. The method works!
Thanks,
Shubham
PayPal, Inc.

