Skip to content

Request for a common replacement for the locale.atof function #3522

@zz912

Description

@zz912

Andy managed to define the rules for converting string to float:
#3499 (review)
http://linuxcnc.org/docs/devel/html/gui/gui-dev-reference.html#_localization_of_float_numbers_in_guis
These rules are based on long discussions and problems with float localization integration.

It follows from these rules that the locale.atof() function should not be used.

At the same time, @c-morley is working on common libraries for GUIs.
https://github.com/LinuxCNC/linuxcnc/tree/master/lib/python/common

I would like to ask him if he would make a common replacement for the local.atof function.

Can be based on the fix created by Sigma1912
#3500

The function should contain:

  1. Removing spaces from the initial string
  2. replacing (,) with (.)
    string_to_float = string_to_float.replace(",", ".")
  3. converting string to float
  4. the whole thing should be enclosed in a Try ... except function
    In case the string contains letters or multiple decimal separators.

For my own needs I could write something like that. But I can't write a shared library that should appear in many places in many GUIs. I don't have that much experience.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions