#!/usr/bin/env python # coding: utf-8 import locale import sys print('\nlocale not loaded') dp = locale.localeconv()["decimal_point"] print ('decimal_point [. or ,] = %c\n' % dp) s = '2%c5' % dp print('base string = %s' % s) v = (s.replace(dp, '.')) print('replace decimal_point with a dot in %s' % s) print('converted string = %s' % v) print('float(converted string) * 2 = %f' % (float(v) * 2)) try : print('locale.atof(base string) = %f' % (locale.atof(s))) print('float(base string) = %f' % (float(s))) except : print('cannot convert %s to float with float(%s)' % (s, s)) print ('---------') locale.setlocale(locale.LC_ALL, '') print('\nlocale loaded') print(locale.getdefaultlocale()) dp = locale.localeconv()["decimal_point"] print ('\ndecimal_point [. or ,] = %c\n' % dp) s = '2%c5' % dp print('base string = %s' % s) v = (s.replace(dp, '.')) print('replace decimal_point with a dot in %s' % s) print('converted string = %s' % v) print('float(converted string) * 2 = %f' % (float(v) * 2)) try : print('locale.atof(base string) = %f' % (locale.atof(s))) print('float(base string) = %f' % (float(s))) except : print('cannot convert %s to float with float(%s)' % (s, s))