From fd80c102fa9f265b9ba5f24f0f0b2bd7c934991b Mon Sep 17 00:00:00 2001
From: Bruce Momjian <bruce@momjian.us>
Date: Sun, 14 Mar 1999 05:12:45 +0000
Subject: [PATCH] =?UTF-8?q?There=20are=20errors=20in=20the=20PGmoney=20cla?=
 =?UTF-8?q?ss=20in=20the=20conversion=20routines=20over=20the=20handling?=
 =?UTF-8?q?=20of=20negative=20numbers=20and=20commas.=20The=20attached=20p?=
 =?UTF-8?q?ath=20attempts=20to=20fix=20these.=20However=20the=20getValue?=
 =?UTF-8?q?=20method=20does=20not=20yet=20insert=20commas=20into=20the=20g?=
 =?UTF-8?q?enerated=20string.=20Also=20in=20getValue=20there=20is=20an=20i?=
 =?UTF-8?q?ncorrect=20assumption=20that=20the=20currency=20symbol=20is=20'?=
 =?UTF-8?q?$',=20it=20should=20of=20course=20be=20'=C2=A3'!.=20I=20have=20?=
 =?UTF-8?q?no=20idea=20on=20how=20to=20go=20about=20fixing=20this=20one.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Alvin
---
 .../jdbc/postgresql/util/PGmoney.java         | 24 +++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/src/interfaces/jdbc/postgresql/util/PGmoney.java b/src/interfaces/jdbc/postgresql/util/PGmoney.java
index 7d9ebf995a4..c2dcb3fad77 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;
+    }
   }
 }
-- 
GitLab