在Java中将double值格式化为Number而不是String

时间:2015-10-05 16:33:58

标签: java json excel export-to-excel

虽然我在Java文件中将金额值定义为Double,但这些值似乎在导出的Excel文件中键入为String。那么,如何强制将这些值导出为Number而不是String?有没有一种特殊的方法可以用于sub sub.put(...)等?

Java类:

import java.io.Serializable;
import tr.com.cs.utility.Utility;

public class FinancePaymentList implements Serializable{

    private static final long serialVersionUID = 5987846930239863477L;  

    private String oid;
    private Double amount; 
    //... other properties      

    public void setAmountDue(Double amount) {
        this.amountDue = amountDue;
    }
}


JSON:

public static String jsonListToExcel (Collection<FinancePaymentList> list) throws TrnaspException {
    try {
        JSONObject obj = new JSONObject();
        JSONArray array = new JSONArray();
        for (FinancePaymentList form : list) {              
            JSONObject sub = new JSONObject();
            sub.put("oid", form.getOid());              
            sub.put("amount", form.getAmount());
            //... other properties
            array.put(sub);
        }
        obj.put("data", array);
        return obj.toString();
    } catch (Exception e) {
        throw new TrnaspException(e);
    }
}

0 个答案:

没有答案