There is the trouble: A numeric field in excel files was represented as string in database. Even though this number was not used for calculation, it seems for some reason, the database designer has kept it that way! Trouble started when the POI library's getNumericCellValue() method returned the numbers in the form of scientific notation. The number 12,345,600 would be returned as 123.456E5. But I need it in plain text 1245600 without scientific notation and grouping of numbers!
Solution to this problem lies in configuring NumberFormat or DecimalFormat class found in the package java.text. Here is solution code:
Double comSysNumber = cell.getNumericCellValue();
NumberFormat f = NumberFormat.getInstance();
f.setGroupingUsed(false);
String refinedNumber = f.format(comSysNumber);
Now the string variable refinedNumber is all set to be stored into my database :-). Hope this becomes useful to others.
7 comments :
thanks, your investigation is really helpful :) appreciated.
This was very useful for me too, thanks!
Thanks a lot. I had the same problem today while reading an Excel file using Apache POI library. Cheers :-)
Thanks - this was just what I was looking for!
Thanks for sharing.... :). it's help alot.
Thank u so much.. i helps a lot
thanks very much for this post.
Post a Comment