Convert Python strings into floats explicitly using the comma or the point as separators

后端 未结 3 1578
逝去的感伤
逝去的感伤 2020-11-27 07:37

How can I explicitly tell python to read a decimal number using the point or the comma as a decimal separator? I don\'t know the localization settings of the PC that will ru

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-27 08:24

    You can use locale.atof

    import locale
    locale.atof('12.3')
    

    http://docs.python.org/2/library/locale.html

提交回复
热议问题