The system of notation of decimal numbers in the Excel files I am dealing with is (I think) the European system (like French and German). So I have numbers like:
- '23,4588'
- '78,056888'
Note that they are in the form of strings. When I try to convert them to float python raises an exception:
>>> float('78,056888')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: could not convert string to float: '78,056888'
Here's how I solve the problem:
try:
decim = int(excel_value)
except ValueError:
remap = {ord(','): '.'}
decim = float(excel_value.translate(remap))
It seems to work as I want.
So my question is: is there a more appropriate python method for solving these kinds of problems?