the handling of negative numbers and commas. The attached path attempts
to fix these.
However the getValue method does not yet insert commas into the
generated string.
Also in getValue there is an incorrect assumption that the currency
symbol is '$', it should of course be '£'!. I have no idea on how to go
about fixing this one.
Alvin
public void setValue(String s) throws SQLException
{
try {
- val = Double.valueOf(s.substring(1)).doubleValue();
+ String s1;
+ boolean negative;
+
+ negative = (s.charAt(0) == '-') ;
+
+ s1 = s.substring(negative ? 2 : 1);
+
+ int pos = s1.indexOf(',');
+ while (pos != -1) {
+ s1 = s1.substring(0,pos) + s1.substring(pos +1);
+ pos = s1.indexOf(',');
+ }
+
+ val = Double.valueOf(s1).doubleValue();
+ val = negative ? -val : val;
+
} catch(NumberFormatException e) {
throw new SQLException("conversion of money failed - "+e.toString());
}
*/
public String getValue()
{
- return "$"+val;
+ if (val < 0) {
+ return "-$" + (-val);
+ }
+ else {
+ return "$"+val;
+ }
}
}