Gson转json的时候double处理少了个0

Gson 转json 的时候 0.00 会转成0.0 ,有没有方式让它转正确,或者转为“0.00” 也可以

可以在GsonBuilder中注册typeAdapter,定制序列化double的过程
[code="java"]
private static final GsonBuilder builder=new GsonBuilder();
builder.registerTypeAdapter(Double.class, new DoubleTypeAdapter());
Gson gson=builder.create();

[/code]
TypeAdapter的实现如下
[code="java"]

class DoubleTypeAdapter implements JsonSerializer{

@Override
public JsonElement serialize(Double d, Type type,
        JsonSerializationContext context) {
    DecimalFormat format=new DecimalFormat("##0.00");
    String temp=format.format(d);
    System.out.println(temp);
    JsonPrimitive pri=new JsonPrimitive(temp);
    return pri;
}

}
[/code]

    A a = new A();
    a.setId(1);
    a.setS1("7.00");
    System.out.println(JsonUtils.objToJosn(a).toString());

我刚才实验了。的确会省略一个0.我最后的做法。。。只能 传入String 。然后往外转了。