Frage

I am using jxl-2.6.3.jar.

I want to display bigdecimals, which are up to 1 decimal point.

If i write like below, then 1.2 is displayed as "1.2" , but 1.0 appears as "1." . I need 0 as well in case of 1.0, i.e "1.0" instead of simply "1." .

BigDecimal number = new BigDecimal(1.0);
NumberFormat dp1 = new NumberFormat("#.#");
WritableCellFormat format = new WritableCellFormat(dp1);
workSheet.addCell(new Number(1, 1, number.doubleValue(),format));

Thanks

War es hilfreich?

Lösung

You should use the number format "#.0". A "#" character indicates that a digit should be there only if necessary to represent the number, and a "0" character indicates that a digit must be there, even if it's unnecessary to represent the number. For further reference, please see the Excel format symbols.

The "#.0" format will work whether you are using NumberFormat in JXL or you are creating a data format string with DataFormat in Apache POI.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top