svn commit: r935137 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/NumberConverters.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r935137 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/NumberConverters.java

lektran
Author: lektran
Date: Sat Apr 17 07:09:11 2010
New Revision: 935137

URL: http://svn.apache.org/viewvc?rev=935137&view=rev
Log:
Fix the StringToBigDecimal converter to not use an interim double value unless it absolutely has to

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/NumberConverters.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/NumberConverters.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/NumberConverters.java?rev=935137&r1=935136&r2=935137&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/NumberConverters.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/NumberConverters.java Sat Apr 17 07:09:11 2010
@@ -20,6 +20,7 @@ package org.ofbiz.base.conversion;
 
 import java.math.BigDecimal;
 import java.math.BigInteger;
+import java.text.DecimalFormat;
 import java.text.NumberFormat;
 import java.text.ParseException;
 import java.util.List;
@@ -37,6 +38,9 @@ public class NumberConverters implements
 
     protected static Number fromString(String str, Locale locale) throws ConversionException {
         NumberFormat nf = NumberFormat.getNumberInstance(locale);
+        if (nf instanceof DecimalFormat) {
+            ((DecimalFormat) nf).setParseBigDecimal(true);
+        }
         try {
             return nf.parse(str);
         } catch (ParseException e) {
@@ -296,10 +300,13 @@ public class NumberConverters implements
         }
 
         public BigDecimal convert(String obj) throws ConversionException {
-            return BigDecimal.valueOf(Double.valueOf(obj));
+            return new BigDecimal(obj);
         }
 
         protected BigDecimal convert(Number number) throws ConversionException {
+            if (number instanceof BigDecimal) {
+                return (BigDecimal) number;
+            }
             return BigDecimal.valueOf(number.doubleValue());
         }
     }