[issue46183] float function errors on negative number string with comma seperator ex: '-1, 234.0'

2021-12-26 Thread Steven D'Aprano

Steven D'Aprano  added the comment:

Aside: for what it is worth, the British style with a middle dot is also not 
supported: float('1ยท234') also raises ValueError.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46183] float function errors on negative number string with comma seperator ex: '-1, 234.0'

2021-12-26 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

The behaviour is correct and not a bug. Commas are not supported when 
converting strings to float.

The allowed format for floats as strings is described in the docs:

https://docs.python.org/3/library/functions.html#float

By the way, the negative sign is irrelevant. Commas are not supported 
regardless of whether there is a negative sign or not.

The difficulty with commas is that it is ambiguous whether float('1,234') 
should interpret the comma as British/American digit grouping separator, and 
return 1234.0, or as the European decimal point, and return 1.234. For good or 
bad, Python has a bias towards English (like most programming languages) and so 
it chooses to only recognise the decimal point as a dot in the British/American 
style, and reject the comma.

If you want to support European-style commas as the decimal point, the easiest 
way is to call float('1,234'.replace(',', '.'))

--
nosy: +steven.daprano
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46183] float function errors on negative number string with comma seperator ex: '-1, 234.0'

2021-12-26 Thread syed shah


New submission from syed shah :

>>> float ('-1,234')
Traceback (most recent call last):
  File "", line 1, in 
ValueError: could not convert string to float: '-1,234'

--
components: Library (Lib)
messages: 409202
nosy: jj.github.jj
priority: normal
severity: normal
status: open
title: float function errors on negative number string with comma seperator ex: 
'-1,234.0'
versions: Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com