permaculture playing cards*
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
Author

Empty for BigDecimal

sakthi kannan reddiar
Greenhorn

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

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

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


Joanne
Jim Yingst
Wanderer
Sheriff

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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Empty for BigDecimal
 
Similar Threads
BigDecimal rounding problem
AtomicBigDecimal class -- interesting find
Returning Multiple Variables
Issue Whie Deploying EJB on JBoss AS 5.1.0...
Changing the exponential number into normal readable number format?