cast to float with comma as decimal separator fails
M-42-J opened this issue · 1 comments
When you have Filemaker users that are using decimal comma instead of point (e.g. French, Swiss, German,...) as input this results in number fields output in xml also with decimal comma. Which results in 'nan' values when casting.
Tried to change FM behavior by setting "Accept-Language: en, en-Us" header doing the request in _do_request() and hoping to get decimal points but that does not seem to work.
So as a quick fix I changed the cast routine like this:
class NumberCast(TypeCast):
def __call__(self, value):
try:
return float(value)
except Exception:
try:
return float(value.replace(',','.'))
except Exception:
# return NaN
return float('nan')
Which fixes the problem for me now.
Hi,
we released version 0.2.3 yesterday. I did not put a systematic to fix your problem but I wrote a short code example on how you can fix it in a more long term way in the docstring of the FmServer class. Hope it fix your problem.
Thanks for your contribution.