From fd80c102fa9f265b9ba5f24f0f0b2bd7c934991b Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Sun, 14 Mar 1999 05:12:45 +0000 Subject: [PATCH] =?utf8?q?There=20are=20errors=20in=20the=20PGmoney=20clas?= =?utf8?q?s=20in=20the=20conversion=20routines=20over=20the=20handling=20o?= =?utf8?q?f=20negative=20numbers=20and=20commas.=20The=20attached=20path?= =?utf8?q?=20attempts=20to=20fix=20these.=20However=20the=20getValue=20met?= =?utf8?q?hod=20does=20not=20yet=20insert=20commas=20into=20the=20generate?= =?utf8?q?d=20string.=20Also=20in=20getValue=20there=20is=20an=20incorrect?= =?utf8?q?=20assumption=20that=20the=20currency=20symbol=20is=20'$',=20it?= =?utf8?q?=20should=20of=20course=20be=20'=C2=A3'!.=20I=20have=20no=20idea?= =?utf8?q?=20on=20how=20to=20go=20about=20fixing=20this=20one.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 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 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; + } } } -- 2.40.0