decimal point character

B

Bror Johansson

Is there a way to 'configure' the built-in conversion function float() to
accept '.' (dot) as decimalpartdelimiter when executing in an
anglo-american-language environment and to accept ',' (comma) when executing
in a language environment where that character is used for the same purpose?

Is there a pure (=working in Windows as well as in UNIX) Python way to find
out what char float() accepts as decimal point in strings?

/BJ
 
B

Ben Finney

Is there a way to 'configure' the built-in conversion function float() to
accept '.' (dot) as decimalpartdelimiter when executing in an
anglo-american-language environment and to accept ',' (comma) when executing
in a language environment where that character is used for the same purpose?

The word you want, rather than "environment", is "locale". The issue of
decimal point separator is one of the "locale conventions", queried via
locale.localeconv().
['en_AU', 'utf']
>>> locale.localeconv()['decimal_point'] '.'
>>> locale.localeconv()['mon_decimal_point']
''
{'mon_decimal_point': '', 'int_frac_digits': 127, 'p_sep_by_space':
127, 'frac_digits': 127, 'thousands_sep': '', 'n_sign_posn': 127,
'decimal_point': '.', 'int_curr_symbol': '', 'n_cs_precedes': 127,
'p_sign_posn': 127, 'mon_thousands_sep': '', 'negative_sign': '',
'currency_symbol': '', 'n_sep_by_space': 127, 'mon_grouping': [],
'p_cs_precedes': 127, 'positive_sign': '', 'grouping': []}

Read about what each of these convention values mean:

<http://www.python.org/doc/lib/module-locale.html>
 
B

Bror Johansson

message ....
The word you want, rather than "environment", is "locale". The issue of
decimal point separator is one of the "locale conventions", queried via
locale.localeconv(). ....
Read about what each of these convention values mean:

<http://www.python.org/doc/lib/module-locale.html>

Excellent answer. I really should have come to think about locale myself,
but ...

.... still some questions:

I don't see anything about the builtin float() adhering to locale
conventions. Am I right to assume that float() behaves according to locale?

Is it "allowed" to modify localeconv()['decimal point'], or are unexpected
sideeffects possible?

/BJ
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,969
Members
47,524
Latest member
ecomwebdesign

Latest Threads

Top