File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Empty for BigDecimal Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Empty for BigDecimal" Watch "Empty for BigDecimal" New topic

Empty for BigDecimal

sakthi kannan reddiar

Joined: Oct 25, 2007
Posts: 3
Hi All,

I've a bean like this:

public String getDelFlag() {
return delFlag;

public void setDelFlag(String delFlag) {
this.delFlag = delFlag;

and I want to set empty value for this and

objName.setDelFlag("") is OKay


public java.math.BigDecimal getNetWeight() {
return netWeight;

public void setNetWeight(java.math.BigDecimal netWeight) {
this.netWeight = netWeight;

for this BigDecimal how do I set a empty value. Setting this value is a must.

My appraches to have
objName.setNetWeight(new BigDecimal("" or null or " ")) all results in NumberFormatException.

Please advise me how do I handle this?

Thanks in advance,
[ April 24, 2008: Message edited by: sakthi kannan reddiar ]
Joanne Neal

Joined: Aug 05, 2005
Posts: 3742
You can't. From the BigDecimal(String) constructor javadoc
The string must contain at least one digit in either the integer or the fraction.

Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
You can call

However if you allow this, then you must write your code so that any time you use the net weight, you consider the possibility that it's null. If you're not careful, there's a good chance you'll get a NullPointerException as a result.

"I'm not back." - Bill Harding, Twister
I agree. Here's the link:
subject: Empty for BigDecimal
It's not a secret anymore!