Przeglądaj źródła

[性能验证]添加相关公式计算

liyuan 2 lat temu
rodzic
commit
0864990d19

+ 23 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/funcs/TestFuncs.java

@@ -0,0 +1,23 @@
+package com.lc.ibps.components.verification.funcs;
+
+public class TestFuncs {
+    public static void main(String[] args){
+        double[] cNode1 = {25.30 ,28.40 ,32.50 ,36.90 ,42.70 ,49.80 ,55.10 ,62.30 ,65.40 ,69.70 ,85.40 ,89.60 ,91.30 ,99.40 ,105.60 ,135.40 ,162.40 ,173.40 ,184.50 ,192.60 ,203.60 ,219.80 ,235.60 ,233.70 ,216.90 ,265.80 ,272.60 ,288.80 ,294.60 ,309.40 ,335.60 ,356.40 ,342.90 ,365.70 ,385.40 ,376.30 ,402.00 ,415.00 ,426.90 ,468.0};
+        double[] cNode2 = {26.40 ,29.30 ,33.50 ,35.90 ,43.10 ,50.90 ,56.80 ,63.40 ,62.70 ,72.40 ,88.10 ,90.30 ,90.60 ,98.40 ,102.70 ,130.60 ,165.90 ,170.60 ,186.50 ,199.40 ,203.50 ,220.70 ,234.90 ,236.70 ,210.90 ,270.10 ,276.40 ,290.00 ,298.00 ,310.00 ,339.00 ,354.00 ,343.00 ,369.00 ,387.00 ,372.00 ,404.00 ,416.00 ,429.00 ,470.00};
+        xFuncStdevVar stdev =new xFuncStdevVar();
+        xValue xValue1 = stdev.evalArgs(cNode1, xFuncStdevVar.iSTDEV);
+        xValue xValue2 = stdev.evalArgs(cNode2, xFuncStdevVar.iSTDEV);
+        System.out.println(xValue1.getDoub());
+        System.out.println(xValue2.getDoub());
+
+        xFuncArray2Args xfuncs = new xFuncArray2Args();
+        xValue b = xfuncs.evalArgs(cNode2,cNode1,  xFuncArray2Args.iSLOPE);
+        System.out.println(b.getDoub());
+
+        xValue a = xfuncs.evalArgs(cNode2,cNode1,  xFuncArray2Args.iINTERCEPT);
+        System.out.println(a.getDoub());
+
+        xValue r = xfuncs.evalArgs(cNode2,cNode1,  xFuncArray2Args.iCORREL);
+        System.out.println(r.getDoub());
+    }
+}

+ 123 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/funcs/xFuncArray2Args.java

@@ -0,0 +1,123 @@
+package com.lc.ibps.components.verification.funcs;
+
+import lombok.val;
+
+import java.io.Serializable;
+
+public class xFuncArray2Args implements Serializable {
+    public static int iCOVAR = 0;
+    public static int iCORREL = 1;
+    public static int iINTERCEPT = 2;
+    public static int iPEARSON = 3;
+    public static int iRSQ = 4;
+    public static int iSLOPE = 5;
+    public static int iSTEYX = 6;
+
+    /**
+     * Generic function that helps calculate a function with 2 array arguments,
+     * like COVAR, CORREL, etc.
+     * @param cNod    the result node
+     * @param iFunc   the calling function (0=COVAR, etc)
+     * @return        true if the node has been evaluated successfully
+     */
+    //We may want redo this method in the future in order to make it clearer.
+    public xValue evalArgs(double[] cNod1, double[] cNod2, int iFunc) {
+        xValue valRes = new xValue();
+
+
+        if (cNod1.length == cNod2.length) {
+            int iCnt = cNod1.length;
+            double[][] dblSets = new double[iCnt][2];
+            boolean[] boolSets = new boolean[iCnt];
+
+            //Here we capture both arrays in a single array 'dblSets'
+            //which will contain essentially an array of sets of doubles
+            //'boolSets' keeps track of non-doubles
+            for (int ii = 0; ii < iCnt; ii++) {
+                boolSets[ii] = true;
+                dblSets[ii][0] = cNod1[ii];
+                dblSets[ii][1] = cNod2[ii];
+            }
+
+            //Here we calculate generic intermediate results
+            int nn = 0;
+
+            double xx = 0;
+            double yy = 0;
+            double xy = 0;
+            double xx2 = 0;
+            double yy2 = 0;
+            boolean bEmpty = true;
+            for (int ii = 0; ii < iCnt; ii++) {
+                if (boolSets[ii]) {
+                    bEmpty = false;
+                    nn++;
+                    xx = xx + dblSets[ii][0];
+                    yy = yy + dblSets[ii][1];
+                    xy = xy + dblSets[ii][0] * dblSets[ii][1];
+                    xx2 = xx2 + dblSets[ii][0] * dblSets[ii][0];
+                    yy2 = yy2 + dblSets[ii][1] * dblSets[ii][1];
+                }
+            }
+
+            //Here is where we actually perform an operation on the arrays,
+            //depending on the calling function
+            if (bEmpty && ((iFunc == iCOVAR) || (iFunc == iCORREL))) {
+                valRes.setErrDiv();
+            } else if (bEmpty) {
+                valRes.setErrNa();
+            } else if (iFunc == iINTERCEPT || (iFunc == iSLOPE)) {
+                double denom = nn * yy2 - yy * yy;
+                if (denom == 0) {
+                    valRes.setErrDiv();
+                } else if (iFunc == iINTERCEPT) {
+                    valRes.setVal(xx / nn - yy / nn * (nn * xy - xx * yy) / denom);
+                } else if (iFunc == iSLOPE) {
+                    valRes.setVal((nn * xy - xx * yy) / denom);
+                }
+            } else if (iFunc == iPEARSON || (iFunc == iRSQ)) {
+                double denom = Math.pow((nn * xx2 - xx * xx) * (nn * yy2 - yy * yy), 0.5);
+                if (denom == 0) {
+                    valRes.setErrDiv();
+                } else if (iFunc == iPEARSON) {
+                    valRes.setVal((nn * xy - xx * yy) / denom);
+                } else if (iFunc == iRSQ) {
+                    valRes.setVal(Math.pow((nn * xy - xx * yy) / denom, 2));
+                }
+            } else if (iFunc == iSTEYX) {
+                double denom1 = nn * (nn - 2);
+                double denom2 = nn * yy2 - yy * yy;
+                if ((denom1 == 0) || (denom2 == 0)) {
+                    valRes.setErrDiv();
+                } else {
+                    valRes.setVal(Math.pow(1.0 / denom1 * (nn * xx2 - xx * xx - Math.pow(nn * xy - yy * xx, 2) / denom2), 0.5));
+                }
+            } else if ((iFunc == iCOVAR) || (iFunc == iCORREL)) {
+                double dAvgx = xx / nn;
+                double dAvgy = yy / nn;
+                double dCovar = 0;
+                for (int ii = 0; ii < iCnt; ii++) {
+                    if (boolSets[ii]) {
+                        dCovar = dCovar + (dblSets[ii][0] - dAvgx) * (dblSets[ii][1] - dAvgy);
+                    }
+                }
+                if (iFunc == iCOVAR) {
+                    valRes.setVal(dCovar / nn);
+                } else if (iFunc == iCORREL) {
+                    double dStdevX = Math.pow((nn * xx2 - Math.pow(xx, 2.0)) / (nn * nn), 0.5);
+                    double dStdevY = Math.pow((nn * yy2 - Math.pow(yy, 2.0)) / (nn * nn), 0.5);
+                    if ((dStdevX == 0) || (dStdevY == 0)) {
+                        valRes.setErrDiv();
+                    } else {
+                        valRes.setVal((dCovar / nn) / (dStdevX * dStdevY));
+                    }
+                }
+            }
+        } else {
+            valRes.setErrNa();
+        }
+
+        return valRes;
+    }
+}
+

+ 50 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/funcs/xFuncStdevVar.java

@@ -0,0 +1,50 @@
+package com.lc.ibps.components.verification.funcs;
+
+import java.io.Serializable;
+
+public class xFuncStdevVar implements Serializable {
+    public static int iSTDEV = 0;
+    public static int iSTDEVA = 1;
+    public static int iSTDEVP = 2;
+    public static int iSTDEVPA = 3;
+    public static int iVAR = 4;
+    public static int iVARA = 5;
+    public static int iVARP = 6;
+    public static int iVARPA = 7;
+
+    /**
+     * Generic function that helps calculate a function with 1+ arguments,
+     * The arguments could be 1 or more.
+     * @param cNod    the result node
+     * @param iFunc   the calling function (0=STDEV, etc)
+     * @return        true if the node has been evaluated successfully
+     */
+    //We may want redo this method in the future in order to make it clearer.
+    public xValue evalArgs(double[] cNod, int iFunc) {
+        xValue valRes = new xValue();
+
+        double dBuff = 0;
+        double xx = 0;
+        double xx2 = 0;
+        long nn = 0;
+        for (int ii = 0; ii < cNod.length; ii++) {
+            dBuff = cNod[ii];
+            xx += dBuff;
+            xx2 += Math.pow(dBuff, 2);
+            nn++;
+        }
+
+        if (iFunc == iVAR || iFunc == iVARA) {
+            valRes.setVal((nn * xx2 - Math.pow(xx, 2)) / (nn * (nn - 1)));
+        } else if (iFunc == iVARP || iFunc == iVARPA) {
+            valRes.setVal((nn * xx2 - Math.pow(xx, 2)) / Math.pow(nn, 2));
+        } else if (iFunc == iSTDEV || iFunc == iSTDEVA) {
+            valRes.setVal(Math.pow((nn * xx2 - Math.pow(xx, 2)) / (nn * (nn - 1)), 0.5));
+        } else if (iFunc == iSTDEVP || iFunc == iSTDEVPA) {
+            valRes.setVal(Math.pow((nn * xx2 - Math.pow(xx, 2)) / Math.pow(nn, 2), 0.5));
+        }
+
+        return valRes;
+    }
+}
+

+ 598 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/funcs/xValue.java

@@ -0,0 +1,598 @@
+package com.lc.ibps.components.verification.funcs;
+
+import java.io.Serializable;
+import java.text.DecimalFormat;
+
+public class xValue implements Serializable {
+    private static final byte iNULL = 0;
+    private static final byte iDOUBLE = 1;
+    private static final byte iSTRING = 2;
+    private static final byte iBOOLEAN = 3;
+    private static final byte iREF = 4;
+    private static final byte iOBJECT = 5;
+    private static final byte iNOERR = 6;  //From this point up are Errors
+    private static final byte iERRDIV = 7;
+    private static final byte iERRNA = 8;
+    private static final byte iERRNAME = 9;
+    private static final byte iERRNULL = 10;
+    private static final byte iERRNUM = 11;
+    private static final byte iERRREF = 12;
+    private static final byte iERRVALUE = 13;
+    private static final byte iERRGEN = 14;
+
+    private static final String sERRDIV = "#DIV/0!";
+    private static final String sERRNA = "#N/A";
+    private static final String sERRNAME = "#NAME?";
+    private static final String sERRNULL = "#NULL!";
+    private static final String sERRNUM = "#NUM!";
+    private static final String sERRREF = "#REF!";
+    private static final String sERRVALUE = "#VALUE!";
+
+    /** @deprecated - this attribute is OBFUSCATED for clients. Replace the start of this line for developer javadocs. */
+    public static final String sERRGEN = "#ERROR!";
+
+    //Attributes
+    private byte iType = iNULL;
+    private double valDoub;
+    private Object valObj = null;  //Originally this was a String declaration
+
+    //============SET METHOD SECTION============
+
+    /**
+     * Stores the attributes of valX
+     * @param valX  the value to store
+     */
+    public void setVal(xValue valX) {
+        iType = valX.iType;
+        if (!isErr()) {
+            if ((iType == iDOUBLE) || (iType == iBOOLEAN)) {
+                valDoub = valX.valDoub;
+            } else {
+                valObj = valX.valObj;
+            }
+        }
+    }
+
+    /**
+     * Stores the double, valD
+     * @param valD  the double to store
+     */
+    public void setVal(double valD) {
+        if (Double.isNaN(valD)) {
+            iType = iERRNUM;
+        } else {
+            iType = iDOUBLE;
+            valDoub = valD;
+        }
+    }
+
+    /**
+     * Stores the boolean, valB
+     * @param valB  the boolean to store
+     */
+    public void setVal(boolean valB) {
+        iType = iBOOLEAN;
+        valDoub = (valB ? 1 : 0);
+    }
+
+    /**
+     * Stores the String, valS
+     * @param valS  the String to store
+     */
+    public void setVal(String valS) {
+        iType = iSTRING;
+        valObj = valS;
+    }
+
+
+
+    /**
+     * Stores the Object, valO
+     * @param valO  the Object to store
+     */
+    public void setVal(Object valO) {
+        iType = iOBJECT;
+        valObj = valO;
+    }
+
+    /**
+     * Formats and stores a String in the xValue.
+     * If valS can be converted into a double, date or boolean,
+     * it is stored as such, with all non-numeric symbols removed.
+     * @param valS  the String to format and store
+     */
+    public void setValFormat(String valS) {
+        setValFormat(valS, false);
+    }
+
+    /**
+     * Formats and stores a String in the xValue.
+     * If valS can be converted into a double, date or boolean,
+     * it is stored as such, with all non-numeric symbols removed.
+     * @param valS    the String to format and store
+     * @param bNull   if TRUE, empty strings are set to null
+     */
+    public void setValFormat(String valS, boolean bNull) {
+        //****Needs Work****
+        try {
+            if (valS.lastIndexOf("'") >= 0) {
+                iType = iSTRING;
+                valObj = valS;
+            } else if (valS.length() == 0) {
+                if (bNull) {
+                    iType = iNULL;
+                    valObj = null;
+                } else {
+                    iType = iSTRING;
+                    valObj = valS;
+                }
+            } else {
+                try {
+                    if (valS.indexOf("/") == -1) {
+                        valDoub = getDoubFromStr(valS);
+                    }
+                    iType = iDOUBLE;
+                } catch (NumberFormatException e) {
+                    if (valS.compareToIgnoreCase("TRUE") == 0) {
+                        iType = iBOOLEAN;
+                        valDoub = 1;
+                    } else if (valS.compareToIgnoreCase("FALSE") == 0) {
+                        iType = iBOOLEAN;
+                        valDoub = 0;
+                    } else if (valS.charAt(0) == '#') {
+                        if (valS.equalsIgnoreCase(sERRNA)) {
+                            iType = iERRNA;
+                        } else if (valS.equalsIgnoreCase(sERRDIV)) {
+                            iType = iERRDIV;
+                        } else if (valS.equalsIgnoreCase(sERRNAME)) {
+                            iType = iERRNAME;
+                        } else if (valS.equalsIgnoreCase(sERRNULL)) {
+                            iType = iERRNULL;
+                        } else if (valS.equalsIgnoreCase(sERRNUM)) {
+                            iType = iERRNUM;
+                        } else if (valS.equalsIgnoreCase(sERRREF)) {
+                            iType = iERRREF;
+                        } else if (valS.equalsIgnoreCase(sERRVALUE)) {
+                            iType = iERRVALUE;
+                        } else {
+                            iType = iSTRING;
+                            valObj = valS;
+                        }
+                    } else {
+                        iType = iSTRING;
+                        valObj = valS;
+                    }
+                }
+            }
+        } catch (Exception e) {
+            iType = iSTRING;
+            valObj = valS;
+        }
+    }
+
+
+    //============GET METHOD SECTION============
+
+    /**
+     * Returns the double equivalent of current object.
+     * If object can be converted into a double, it is returned as such,
+     * with all non-numeric symbols removed.
+     * @return  the double equivalent
+     */
+    public double getDoub() {
+        //****Needs Work****
+        if ((iType == iDOUBLE) || (iType == iBOOLEAN)) {
+            return valDoub;
+        } else if (iType == iSTRING) {
+            String sBuff = (String) valObj;
+            if (sBuff.length() == 0) {
+                return 0;
+            } else {
+                return getDoubFromStr(sBuff);
+            }
+        }  else {
+            return 0;
+        }
+    }
+
+    /**
+     * Returns the boolean equivalent of current object.
+     * If object can be converted into a boolean, it is returned as such.
+     * @return  the boolean equivalent
+     */
+    public boolean getBool() {
+        if ((iType == iDOUBLE) || (iType == iBOOLEAN)) {
+            return (valDoub != 0);
+        } else if (iType == iSTRING) {
+            String sBuff = (String) valObj;
+            if (sBuff.length() == 0) {
+                return false;
+            } else if (sBuff.compareToIgnoreCase("TRUE") == 0 || sBuff.compareToIgnoreCase("'TRUE") == 0) {
+                return true;
+            } else if (sBuff.compareToIgnoreCase("FALSE") == 0 || sBuff.compareToIgnoreCase("'FALSE") == 0) {
+                return false;
+            } else {
+                throw new NumberFormatException();
+            }
+        }  else {
+            return false;
+        }
+    }
+
+    /**
+     * Returns the String representation of current object.
+     * @return  the String equivalent
+     */
+    public String getStr() {
+        if (iType == iDOUBLE) {
+            String sTemp;
+            if (Math.round(valDoub) == valDoub) {
+                Double dNum = new Double(valDoub);
+                sTemp = Long.toString(dNum.longValue());
+                dNum = null;
+            } else {
+                DecimalFormat df = new DecimalFormat("#.###############");
+                sTemp = df.format(valDoub);
+            }
+            return sTemp;
+        } else if (iType == iBOOLEAN) {
+            if (valDoub != 0) {
+                return "TRUE";
+            } else {
+                return "FALSE";
+            }
+        } else if (iType == iSTRING) {
+            if (valObj == null) {
+                return "";
+            } else {
+                return (String) valObj;
+            }
+        } else if (iType == iNULL) {
+            return "";
+        }  else if (iType == iOBJECT) {
+            return valObj.toString();
+        } else {
+            return getStrErr();
+        }
+    }
+
+
+    /**
+     * Returns the current object.
+     * @return  the object
+     */
+    public Object getObj() {
+        if (iType == iOBJECT) {
+            return valObj;
+        } else if (iType == iSTRING) {
+            return valObj;
+        } else if (iType == iREF) {  //This technically should never be called - we should use getRng
+            return valObj;
+        } else if (iType == iDOUBLE) {
+            return new Double(valDoub);
+        } else if (iType == iBOOLEAN) {
+            return new Long((long) getDoub());
+        } else {
+            return null;
+        }
+    }
+
+    //============IS METHOD SECTION============
+
+    /**
+     * Returns TRUE if the object is of type double.
+     * @return  TRUE if double
+     */
+    public boolean isDoub() {
+        return iType == iDOUBLE;
+    }
+
+    /**
+     * Returns TRUE if the object is of type String.
+     * @return  TRUE if String
+     */
+    public boolean isStr() {
+        return (iType == iSTRING) || (iType == iNULL);
+    }
+
+    /**
+     * Returns TRUE if the object is of really String (ie not NULL) - used for ISTEXT function.
+     * @return  TRUE if String
+     */
+    public boolean isStrReally() {
+        return (iType == iSTRING);
+    }
+
+    /**
+     * Returns TRUE if the object is of type boolean.
+     * @return  TRUE if boolean
+     */
+    public boolean isBool() {
+        return iType == iBOOLEAN;
+    }
+
+    /**
+     * Returns TRUE if the object is of type reference.
+     * @return  TRUE if reference
+     */
+    public boolean isRef() {
+        return iType == iREF;
+    }
+
+    /**
+     * Returns TRUE if the object is of type Object.
+     * @return  TRUE if Object
+     */
+    public boolean isObj() {
+        return iType == iOBJECT;
+    }
+
+    //============SET ERR METHOD SECTION============
+
+    /**
+     * Stores the Error related attributes of valX in current object.
+     * This is similar to setVal(xValue valX), only valX is known to
+     * contain an error.  It is provided for optimization purposes.
+     * @param valX  the error
+     */
+    public void setValErr(xValue valX) {
+        iType = valX.iType;
+    }
+
+    /**
+     * Store a #DIV/0! error in the object.
+     */
+    public void setErrDiv() {
+        iType = iERRDIV;
+    }
+
+    /**
+     * Store an #N/A error in the object.
+     */
+    public void setErrNa() {
+        iType = iERRNA;
+    }
+
+    /**
+     * Store a #NAME! error in the object.
+     */
+    public void setErrName() {
+        iType = iERRNAME;
+    }
+
+    /**
+     * Store a #NULL! error in the object.
+     */
+    public void setErrNull() {
+        iType = iERRNULL;
+    }
+
+    /**
+     * Store a #NUM! error in the object.
+     */
+    public void setErrNum() {
+        iType = iERRNUM;
+    }
+
+    /**
+     * Store a #REF! error in the object.
+     */
+    public void setErrRef() {
+        iType = iERRREF;
+    }
+
+    /**
+     * Store a #VALUE! error in the object.
+     */
+    public void setErrVal() {
+        iType = iERRVALUE;
+    }
+
+    /**
+     * Store a non-Excel (generic) error in the object.
+     */
+    public void setErrGen() {
+        iType = iERRGEN;
+    }
+
+
+    //============GET ERR METHOD SECTION============
+
+    /**
+     * Returns TRUE if the current value is an error.
+     * @return  TRUE if error
+     */
+    public boolean isErr() {
+        return iType > iNOERR;
+    }
+
+    /**
+     * Returns TRUE if the current value is an error, but not a #N/A error.
+     * @return  TRUE if non-#N/A error
+     */
+    public boolean isErrButNA() {
+        return (iType > iNOERR && iType != iERRNA);
+    }
+
+    /**
+     * Returns the String representation of the Error.
+     * @return  the string error
+     */
+    public String getStrErr() {
+        if (iType == iERRDIV) {
+            return sERRDIV;
+        } else if (iType == iERRNA) {
+            return sERRNA;
+        } else if (iType == iERRNAME) {
+            return sERRNAME;
+        } else if (iType == iERRNULL) {
+            return sERRNULL;
+        } else if (iType == iERRNUM) {
+            return sERRNUM;
+        } else if (iType == iERRREF) {
+            return sERRREF;
+        } else if (iType == iERRVALUE) {
+            return sERRVALUE;
+        } else {
+            return sERRGEN;
+        }
+    }
+
+    /**
+     * Returns TRUE if the current value is a blank or null value.
+     * @return  TRUE if blank
+     */
+    public boolean isBlank() {
+        if ((iType == iNULL) || (iType == iSTRING && (((String) valObj).length() == 0))) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * Returns TRUE if the current value is a null value.
+     * @return  TRUE if null
+     */
+    public boolean isEmptyString() {
+        if ((iType == iSTRING) && (((String) valObj).length() == 0)) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    //============GET TYPE METHOD SECTION============
+
+    /**
+     * Returns an int value representing the type of value stored
+     * in the current object.
+     * @return  the type
+     */
+    public byte getTyp() {
+        return iType;
+    }
+
+    //============GET??FROMSTR METHOD SECTION============
+
+    /**
+     * Returns a double from a string - if possible
+     * @param sTemp   the string
+     * @return        the double
+     */
+    private double getDoubFromStr(String sOrig) {
+        sOrig = sOrig.trim();
+        while (sOrig.charAt(0) == '+') {
+            sOrig = sOrig.substring(1);
+        }
+
+        int ii = 0;
+        int iLen = sOrig.length();
+        StringBuffer sb = new StringBuffer();
+        boolean bPer = false;
+
+        //Handle $, % and paren negatives
+        if (iLen > 2) {
+            char chr1 = sOrig.charAt(0);
+            if ((chr1 == '-') && (sOrig.charAt(1) == '$')) {
+                sb.append('-');
+                ii = ii + 2;
+            } else {
+                char chr4 = sOrig.charAt(iLen - 1);
+                boolean bNoDolOrPerFound = true;
+                if (chr1 == '$') {
+                    ii++;
+                    chr1 = sOrig.charAt(1);
+                    bNoDolOrPerFound = false;
+                } else if (chr4 == '%') {
+                    bPer = true;
+                    chr4 = sOrig.charAt(iLen - 2);
+                    iLen--;
+                    bNoDolOrPerFound = false;
+                }
+                if ((chr1 == '(') && (chr4 == ')')) {
+                    sb.append('-');
+                    ii++;
+                    iLen--;
+                    if (bNoDolOrPerFound) {
+                        if (sOrig.charAt(1) == '$') {
+                            ii++;
+                        } else if (sOrig.charAt(iLen - 1) == '%') {  //We already subtracted once, so -1 instead of -2
+                            bPer = true;
+                            iLen--;
+                        }
+                    }
+                }
+            }
+        } else if (iLen == 2) {
+            if (sOrig.charAt(0) == '$') {
+                ii++;
+            } else if (sOrig.charAt(1) == '%') {
+                bPer = true;
+                iLen--;
+            }
+        }
+
+        boolean bNum = true;
+
+        char chr = 0;
+        for (; (ii < iLen) && bNum; ii++) {
+            chr = sOrig.charAt(ii);
+            if (Character.isDigit(chr) || (chr == '-') || (chr == '.') || (chr == 'E')) {
+                sb.append(chr);
+            } else if (chr == ',') {
+                //Look ahead
+                if (!Character.isDigit(sOrig.charAt(ii + 1)) ||!Character.isDigit(sOrig.charAt(ii + 2)) ||!Character.isDigit(sOrig.charAt(ii + 3))) {
+                    bNum = false;
+                }
+            } else {
+                bNum = false;
+            }
+        }
+        if (!bNum) {
+            throw new NumberFormatException();
+        } else {
+            //The code below replaces the commented code below it, so that we don't get more decimals than necessary
+            if (bPer) {  //It will bomb here if not double
+                boolean bNeg = (sb.charAt(0) == '-');
+                if (bNeg) {
+                    sOrig = "000" + sb.toString().substring(1);
+                } else {
+                    sOrig = "000" + sb.toString();
+                }
+
+                int iDec = sOrig.indexOf(".");
+                if (iDec == -1) {
+                    iDec = sOrig.length();
+                } else {
+                    sOrig = sOrig.substring(0, iDec) + sOrig.substring(iDec + 1);
+                }
+                iDec = iDec - 2;
+                if (bNeg) {
+                    return -Double.parseDouble(sOrig.substring(0, iDec) + "." + sOrig.substring(iDec));
+                } else {
+                    return Double.parseDouble(sOrig.substring(0, iDec) + "." + sOrig.substring(iDec));
+                }
+            } else {
+                return Double.parseDouble(sb.toString());
+            }
+
+      /*if (bPer) { //It will bomb here if not double
+        return Double.parseDouble(sTemp) / 100;
+      } else {
+        return Double.parseDouble(sTemp);
+      }*/
+        }
+    }
+
+
+    //============CLEANUP SECTION============
+
+    /**
+     * Cleans up the instance of the class.
+     * Used to set all objects to null so that they can be released.
+     */
+    public void cleanUp() {
+        valObj = null;
+    }
+}