Ejemplo n.º 1
0
        public Object call(Scope sc, Object pointsInt, Object fo00000o[]) {
          Number n = (Number) (sc.getThis());
          int num = 0;
          if (pointsInt != null && pointsInt instanceof Number)
            num = ((Number) pointsInt).intValue();

          double mult = Math.pow(10, num);

          long foo = Math.round(n.doubleValue() * mult);
          double d = foo;
          d = d / mult;

          String s = String.valueOf(d);
          int idx = s.indexOf(".");

          if (idx < 0) {
            if (num > 0) {
              s += ".";
              while (num > 0) {
                s += "0";
                num--;
              }
            }
            return new JSString(s);
          }

          if (s.length() - idx <= num) { // need more
            int toAdd = (num + 1) - (s.length() - idx);
            for (int i = 0; i < toAdd; i++) s += "0";
            return new JSString(s);
          }

          if (num == 0) return s.substring(0, idx);
          return new JSString(s.substring(0, idx + 1 + num));
        }
Ejemplo n.º 2
0
 public Object call(Scope s, Object foo[]) {
   Number n = (Number) s.getThis();
   return n.doubleValue() * _conversion;
 }