Skip to content

In some locales, the decimal separators is a comma #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed

Conversation

yarkm13
Copy link

@yarkm13 yarkm13 commented Feb 9, 2025

It seems that the ps command respects locale settings and uses different decimal separators depending on the locale. For example, the Ukrainian (uk) locale uses a comma as the decimal separator instead of a period so CPU and MEM usage numbers are shown as 12,4. As a result, strconv.ParseFloat fails to parse floating-point numbers in the following lines of the getProcessList() function:

cpu, _ := strconv.ParseFloat(fields[2], 64)
mem, _ := strconv.ParseFloat(fields[3], 64)

A more universal solution could involve checking the current locale, determining the decimal separator, or using a third-party module. However, in practice, there are only two common cases: a comma or a period. For this specific use case, simply replacing the comma with a period before parsing should be sufficient.

BTW powermetrics -s tasks didn't respect locale settings and used period as decimal separator.

@yarkm13 yarkm13 changed the base branch from main to development February 10, 2025 23:44
@yarkm13 yarkm13 closed this Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

All CPU and MEM values shown as 0.0 in some locales
3 participants