java - Format number with thousands separator in Excel using Apache POI -


i want format number cells, comma thousands separator. example:

12        -> 12 1200      -> 1,200 12000     -> 12,000 12000000  -> 12,000,000 120000000 -> 120,000,000 

i have following code. should use formatstr? there easy way? or have detect number of zeros in order produce #,###,###?

string formatstr = ""; hssfcellstyle style = workbook.createcellstyle(); hssfdataformat format = workbook.createdataformat(); style.setdataformat(format.getformat(formatstr)); cell.setcellstyle(style); cell.setcelltype(hssfcell.cell_type_numeric); 

keep in mind i'm dealing numbers. cell type numeric, not string.

update

enter image description here

just #,### or #,##0 should sufficient. excel interprets having thousands separators every 3 digits (not before last three, infer expecting).

enter image description here

in spirit of teaching man fish, how can find out yourself:

format number, 0 decimal places, 1000 separator:

enter image description here

click ok, re-open number format dialog , go custom. have @ formatting code ("type"). says #,##0, me gives exact same result #,###.

enter image description here


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -