PDA

View Full Version : Float to String is not converted properly


OCTAGRAM2
08-31-2010, 11:39 AM
Hello!

Float numbers had "," instead of "." in Russian locale. Due to this issue Quercus issued queries like this:

UPDATE table_name SET field = field + 0,25000000 WHERE ...

The patch is very simple:

resin-4.0.9/modules/quercus/src/com/caucho/quercus/env/DoubleValue.java.patch

--- DoubleValue.java.old 2010-07-29 11:25:40.000000000 +0700
+++ DoubleValue.java 2010-08-31 18:09:58.796875000 +0700
@@ -36,6 +36,7 @@
import java.io.PrintWriter;
import java.io.Serializable;
import java.util.IdentityHashMap;
+import java.util.Locale;

/**
* Represents a PHP double value.
@@ -418,7 +419,7 @@
else if (digits < 0)
digits = 0;

- String v = String.format("%." + digits + "f", _value);
+ String v = String.format(Locale.US, "%." + digits + "f", _value);

int len = v.length();
int nonzero = -1;
@@ -444,7 +445,7 @@
return v;
}
else
- return String.format("%.13E", _value);
+ return String.format(Locale.US, "%.13E", _value);
}

/**


Also, I had to patch in a similar way sprintf() and microtime() implementations.