Hey Mark, Don't be worried, it all seems to work, at least enough to go on... One thing I do not understand, is what you mean with getting the value as a double, and then formatting it? The formatCellValue works on the cell itself, not on a double as far as I know? Anyay, the code as printed in my last comment seem to work.
Thanks again for your time, regards, frank > -----Original Message----- > From: MSB [mailto:[email protected]] > Sent: dinsdag 10 maart 2009 17:18 > To: [email protected] > Subject: RE: Number Formatting in HSSF > > > Glad to know that all of that was of some help, must admit I worried > after > reading it back. > > If you do ultimately want the number as a String, have you tried > getting the > cell value as a double and then formatting it using the > formatCellValue() > method yet? You may be lucky and find that the format set for the cell > manages to circumvent some of your problems and of course the > formatCellValue() method returns a String ready for inclusion into the > xml > file. The only catch that I can think of is if the user has set a > format > that includes - for example - five digits after the decimal point and > then > they enter a floating point value with just four digits following the > decimal point. > > Getting rid of Office has been a double edged sword in many ways - you > would > be surprised how 'exercised' users can be when an operation they > performed > with Excel is simply not supported by OpenOffice Calc; just as an > example, > you can select many different rows in Excel and delete the lot, Calc > will > not alow you to delete a series of non contiguous rows. Lots of fun. > > > Frank Prins wrote: > > > > Hello Mark, > > > > Thank you for your extensive answer, it is getting a bit more clear > for > > me now, although I run into difficulties with not being able to > > duplicate the problem. > > > > It definitively has to do with the float to double conversion here. > > Using getNumericCellValue() sometimes returns me a value not being > > exactly the value entered by the user. For example, I am looking at a > > field in which the user entered the value 7,8268 > > This looks like a number with four decimals, but somehow when using > > getNumericCellValue() it shows up as being 7.8267999999999995. > Strange > > thing is I cannot duplicate this, when typing the number in myself, > it > > keeps showing up like 7.8268, so correct. > > Anyhow, I experimented a bit more with the retrieval of the value, > and > > found out I can overcome the above issue when casting to a float, > like: > > > > double doubleValue = cell.getNumericCellValue(); > > // format the number as floating point: > > value = String.valueOf((float) doubleValue); > > > > In this case I get exactly what the user originally used as input. > > BTW, in my code, I indeed do a check on celltype. I tried to copy > just > > the part of code necessary for the issue I had... > > Oh, and getting the value as a string.... I am writing the values to > an > > XML file, so that's why I took it as a String, no need for further > math > > here. > > > > Thanks, > > Frank > > > > PS I can only dream of an Office-less office :-) > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [email protected] > > For additional commands, e-mail: [email protected] > > > > > > > > -- > View this message in context: http://www.nabble.com/Number-Formatting- > in-HSSF-tp22408718p22437871.html > Sent from the POI - User mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
