Hi,
The format string you are getting, "0.00", is telling
you that there are 2 decimal places because there are
two zeroes after the decimal point. It's up to you to
then make use of that information to round the value in
the cell to that many decimal places.
And I agree that floating point numbers in cells are
useless without knowing how many digits they need to be
rounded to in order to match the expectations of humans
looking at the spreadsheets.
Warning: The xlrd module handles getting formatting
information for .xls files but not for .xlsx files,
even though it can read the values in them. For .xlsx
files, you need to use the openpyxl module instead
to obtain the formatting information.
Attached is a module/program that does this. As a
module, it provides the same API for reading csv, xls,
and xlsx files (i.e. obtaining all cells as text). As a
program, it outputs the contents of such files (or an
individual worksheet from them) as csv.
You won't want to use it as is, because it's in Python2
and it converts the character set in csv files from
UTF-32/16/8 to Latin-1 when it encounters it (you don't
want to know). But it does show how to obtain and
interpret the formatting information for both xls and
xlsx files. The only non-standard modules it uses are
xlrd and openpyxl.
Warning: I think that the language of formatting
specifiers is probably very complex in general which is
why libraries don't apply them to the values for you.
But I've been using the attached code for over a decade
to read many many thousands of spreadsheets from many
different people and it's worked well for me (although
the openpyxl code is much more recent). But it's
possible that it won't handle some format specifiers
that you encounter. But probably not. All this code is
doing for numbers is counting the number of zeroes
after the decimal place and rounding accordingly.
cheers,
raf