Package com.extentech.toolkit

Examples of com.extentech.toolkit.CompatibleBigDecimal


          return "-" + num;
        }
        return num;
      }
      preString = num.substring(0, i);
      CompatibleBigDecimal outNumD = new CompatibleBigDecimal(preString);
      String exp = "";
      if (num.indexOf("+") == -1) {
        exp = num.substring(i + 1, num.length());
      } else {
        exp = num.substring(i + 2, num.length());
      }
      int expNum = Integer.valueOf(exp).intValue();
      outNumD = new CompatibleBigDecimal(outNumD.movePointRight(expNum));
      // outNumD = outNumD.multiply(new CompatibleBigDecimal(Math.pow(10,
      // expNum)));
      // Logger.logInfo(String.valueOf(outNumD));
      // outNum = Math.r

      // check if we should be returning a whole number or a decimal
      int moveLen = num.indexOf("E") - num.indexOf(".") - 1;
      if (expNum >= moveLen) {
        if (negative) {
          return "-"
              + String.valueOf(Math.round(outNumD.doubleValue()));
        } else {
          return String.valueOf(Math.round(outNumD.doubleValue()));
        }
      }
      Object[] args = new Object[0];
      // args[0] = outNumD;
      Object res = ResourceLoader.executeIfSupported(outNumD, args,
          "toPlainString");
      if (res != null) {
        fullString = res.toString();
      } else {
        fullString = outNumD.toCompatibleString();
      }
      break;
    case 1: // NOTATION_SCIENTIFIC
      if (num.indexOf("E") != -1 && num.indexOf("+") == -1) {
        fullString = num;
      } else if (num.indexOf("+") != -1) {
        preString = num.substring(0, num.indexOf("+"));
        postString = num.substring(num.indexOf("+") + 1, num.length());
        return preString + postString;
      } else if (num.indexOf(".") != -1) {
        int pos = num.indexOf(".");
        preString = num.substring(0, 1) + "."
            + num.substring(1, num.indexOf("."));
        CompatibleBigDecimal d = new CompatibleBigDecimal(num);
        if (d.doubleValue() < 1 && d.doubleValue() != 0) {
          // it is a very small value, ie 1.0E-10
          int counter = 0;
          while (d.doubleValue() < 1) {
            d = new CompatibleBigDecimal(d.movePointRight(1));
            counter++;
          }
          String retStr = d.toCompatibleString() + "E-" + counter;
          return retStr;
        }
        postString = num.substring(num.indexOf(".") + 1, num.length());
        fullString = preString + postString;
        fullString = fullString + "E" + (pos - 1);
      } else {
        preString = num.substring(0, 1) + ".";
        if (num.length() > 1) {
          preString += num.substring(1, num.length());
        } else {
          preString += "0";
        }
        fullString = preString + "E" + (num.length() - 1);
      }
      break;
    case 2: // NOTATION_SCIENTIFIC_EXCEL
      if (num.indexOf("E") != -1 && num.indexOf("+") != -1) {
        fullString = num;
      } else if (num.indexOf("E") != -1) {
        preString = num.substring(0, num.indexOf("E") + 1);
        postString = "+"
            + num.substring(num.indexOf("E") + 1, num.length());
        fullString = preString + postString;
      } else if (num.indexOf(".") != -1) {
        int pos = num.indexOf(".");
        CompatibleBigDecimal d = new CompatibleBigDecimal(num);
        if (d.doubleValue() < 1 && d.doubleValue() != 0) {
          // it is a very small value, ie 1.0E-10
          int counter = 0;
          while (d.doubleValue() < 1) {
            d = new CompatibleBigDecimal(d.movePointRight(1));
            counter++;
          }
          String retStr = d.toCompatibleString() + "E-" + counter;
          return retStr;
        }
        preString = num.substring(0, 1) + "."
            + num.substring(1, num.indexOf("."));
        postString = num.substring(num.indexOf(".") + 1, num.length());
View Full Code Here

TOP

Related Classes of com.extentech.toolkit.CompatibleBigDecimal

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.