• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Empty for BigDecimal

 
sakthi kannan reddiar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

WHEREAS

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,
Sakthi
[ April 24, 2008: Message edited by: sakthi kannan reddiar ]
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic