summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Momjian1999-03-14 05:12:45 +0000
committerBruce Momjian1999-03-14 05:12:45 +0000
commitfd80c102fa9f265b9ba5f24f0f0b2bd7c934991b (patch)
treeb91e9b265ccafff4ef28ecdc048efd3ae7f0b371
parent817a3e6d394227f715e55ec7e71ee737e9bdb9aa (diff)
There are errors in the PGmoney class in the conversion routines over
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
-rw-r--r--src/interfaces/jdbc/postgresql/util/PGmoney.java24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/interfaces/jdbc/postgresql/util/PGmoney.java b/src/interfaces/jdbc/postgresql/util/PGmoney.java
index 7d9ebf995a..c2dcb3fad7 100644
--- a/src/interfaces/jdbc/postgresql/util/PGmoney.java
+++ b/src/interfaces/jdbc/postgresql/util/PGmoney.java
@@ -48,7 +48,22 @@ public class PGmoney extends PGobject implements Serializable,Cloneable
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());
}
@@ -80,6 +95,11 @@ public class PGmoney extends PGobject implements Serializable,Cloneable
*/
public String getValue()
{
- return "$"+val;
+ if (val < 0) {
+ return "-$" + (-val);
+ }
+ else {
+ return "$"+val;
+ }
}
}