I am trying to write values stored as BigDecimals e.g. 6789456123 to an xls file but I require the xls file to display $6,789,456,123 (As a currency with 0dp. I can do it as a string with this formatting however this ins't ideal). I am using JExcelApi and I am unable to figure out how to do this. Any help would be appreciated.
我试图将存储为bigdecimal的值(例如6789456123)写入xls文件,但我要求xls文件显示$6,789,456,123(作为一种带有0dp的货币)。我可以用这种格式将它作为一个字符串来处理,但是这种格式并不理想)。我正在使用JExcelApi,但是我不知道怎么做。如有任何帮助,我们将不胜感激。
Thanks
谢谢
1 个解决方案
#1
1
Edit: You can convert a BigDecimal to double with the method .doubleValue()
. Changed example to meet your needs.
编辑:可以使用. doublevalue()方法将BigDecimal转换为double。更改示例以满足您的需要。
Try to create a custom NumberFormat like this:
尝试创建这样的自定义数字格式:
NumberFormat dollarCurrency = new NumberFormat(NumberFormat.CURRENCY_DOLLAR + " ###,###,###.00", NumberFormat.COMPLEX_FORMAT);
WritableCellFormat dollarFormat = new WritableCellFormat(dollarCurrency);
n = new Number(column, row, myBigDecimal.doubleValue(), dollarFormat);
s.addCell(n);
You can also read up on many other example here: jxl demo
您还可以在这里阅读许多其他示例:jxl demo
#1
1
Edit: You can convert a BigDecimal to double with the method .doubleValue()
. Changed example to meet your needs.
编辑:可以使用. doublevalue()方法将BigDecimal转换为double。更改示例以满足您的需要。
Try to create a custom NumberFormat like this:
尝试创建这样的自定义数字格式:
NumberFormat dollarCurrency = new NumberFormat(NumberFormat.CURRENCY_DOLLAR + " ###,###,###.00", NumberFormat.COMPLEX_FORMAT);
WritableCellFormat dollarFormat = new WritableCellFormat(dollarCurrency);
n = new Number(column, row, myBigDecimal.doubleValue(), dollarFormat);
s.addCell(n);
You can also read up on many other example here: jxl demo
您还可以在这里阅读许多其他示例:jxl demo