Logo

Programming-Idioms

History of Idiom 146 > diff from v4 to v5

Edit summary for version 5 by cons0l3:
New Python implementation by user [cons0l3]

Version 4

2016-09-07, 21:41:40

Version 5

2016-09-14, 08:41:41

Idiom #146 Convert string to floating point number

Extract floating point value f from its string representation s

Idiom #146 Convert string to floating point number

Extract floating point value f from its string representation s

Extra Keywords
real conversion
Extra Keywords
real conversion
Imports
import locale
Code
s = u'545.2222'
f = float(s)

s = u'545,2222'
locale.setlocale(locale.LC_ALL, 'de')
f = locale.atof(s)
Comments bubble
when working with different locale decimal and thousand seperators you have to use locale.atof
Doc URL
https://docs.python.org/3/library/locale.html?highlight=local#module-locale