This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic