1

如何在 gwt 中从客户端的 double 中删除指数。

public double evaluate(final double leftOperand, final double rightOperand) {
        Double rtnValue = new Double(leftOperand * rightOperand);
            //Require to write code which remove exponent before return
        return rtnValue.doubleValue();
    }

服务器端可以使用 NumberFormat

NumberFormat formatter = new DecimalFormat("#0.00");
        System.out.println(number);
        System.out.println(formatter.format(number));

但是客户端会抛出异常,例如: 16:08:04.190 [ERROR] [vflow] Line 359: No source code is available for type java.text.NumberFormat ; 你忘了继承一个必需的模块吗?

因为 gwt 不包含 lib java.text JRE Emulation Reference

而且我也试过String.format("%.2f", doubleResult);

GWT 不支持 String.format(),还是我在这里做错了什么?

那么我怎样才能避免双倍指数呢?有什么办法吗?

4

2 回答 2

2

尝试将 javascript 与 JSNI 一起使用:

native String format(double num) /*-{

  // ...implemented with JavaScript
  var v = num;
  return "" + v.valueOf();

}-*/;

我现在没有 GWT sdk 来尝试它,但它应该是这样的。

于 2012-07-05T12:21:32.383 回答
0

GWT 中有一个自定义 NumberFormat 可用:http: //google-web-toolkit.googlecode.com/svn/javadoc/2.4/com/google/gwt/i18n/client/NumberFormat.html

由于兼容性原因,GWT 不支持 NumberFormat 和 DateFormat 的 Java API。本页对此进行了描述:https ://developers.google.com/web-toolkit/doc/latest/DevGuideCodingBasicsFormatting

于 2012-07-09T08:44:37.867 回答