toString on floats and doubles should end with .0 javap
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Sun, 18 Nov 2012 19:54:40 +0100
branchjavap
changeset 187391a5d25c0e1
parent 186 123ba97c3718
child 188 51d08c49e9b6
toString on floats and doubles should end with .0
emul/src/main/java/java/lang/Double.java
emul/src/main/java/java/lang/Float.java
vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java
vm/src/test/java/org/apidesign/vm4brwsr/Numbers.java
     1.1 --- a/emul/src/main/java/java/lang/Double.java	Sun Nov 18 19:19:26 2012 +0100
     1.2 +++ b/emul/src/main/java/java/lang/Double.java	Sun Nov 18 19:54:40 2012 +0100
     1.3 @@ -190,7 +190,9 @@
     1.4       * @param   d   the {@code double} to be converted.
     1.5       * @return a string representation of the argument.
     1.6       */
     1.7 -    @JavaScriptBody(args="d", body="return d.toString();")
     1.8 +    @JavaScriptBody(args="d", body="var r = d.toString();"
     1.9 +        + "if (r.indexOf('.') === -1) r = r + '.0';"
    1.10 +        + "return r;")
    1.11      public static String toString(double d) {
    1.12          throw new UnsupportedOperationException();
    1.13      }
     2.1 --- a/emul/src/main/java/java/lang/Float.java	Sun Nov 18 19:19:26 2012 +0100
     2.2 +++ b/emul/src/main/java/java/lang/Float.java	Sun Nov 18 19:54:40 2012 +0100
     2.3 @@ -192,10 +192,8 @@
     2.4       * @param   f   the float to be converted.
     2.5       * @return a string representation of the argument.
     2.6       */
     2.7 -    @JavaScriptBody(args="d", body="return d.toString();")
     2.8      public static String toString(float f) {
     2.9 -        throw new UnsupportedOperationException();
    2.10 -//        return new FloatingDecimal(f).toJavaFormatString();
    2.11 +        return Double.toString(f);
    2.12      }
    2.13  
    2.14      /**
     3.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java	Sun Nov 18 19:19:26 2012 +0100
     3.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java	Sun Nov 18 19:54:40 2012 +0100
     3.3 @@ -140,6 +140,14 @@
     3.4              s
     3.5          );
     3.6      }
     3.7 +
     3.8 +    @Test public void sevenInStringJS() throws Exception {
     3.9 +        String s = Numbers.floatToString();
    3.10 +        assertExec("Should be the same: " + s, 
    3.11 +            "org_apidesign_vm4brwsr_Numbers_floatToStringLjava_lang_String", 
    3.12 +            s
    3.13 +        );
    3.14 +    }
    3.15      
    3.16      private static CharSequence codeSeq;
    3.17      private static Invocable code;
     4.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/Numbers.java	Sun Nov 18 19:19:26 2012 +0100
     4.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/Numbers.java	Sun Nov 18 19:54:40 2012 +0100
     4.3 @@ -64,4 +64,7 @@
     4.4      static String intToString() {
     4.5          return new Integer(5).toString().toString();
     4.6      }
     4.7 +    static String floatToString() {
     4.8 +        return new Float(7.0).toString().toString();
     4.9 +    }
    4.10  }