Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@yarkm13
Copy link

@yarkm13 yarkm13 commented Feb 11, 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.

Fixes #47

…iod, and strconv fails to parse floats when commas are used as the decimal separator.
@AzimovParviz
Copy link

AzimovParviz commented Mar 26, 2025

Is there anything else that could cause this? I cloned your fork and I still see 0.00 in CPU and MEM usage.

LANG="fi_FI.UTF-8"
LC_COLLATE="fi_FI.UTF-8"
LC_CTYPE="fi_FI.UTF-8"
LC_MESSAGES="fi_FI.UTF-8"
LC_MONETARY="fi_FI.UTF-8"
LC_NUMERIC="fi_FI.UTF-8"
LC_TIME="fi_FI.UTF-8"
LC_ALL=

Here is my locale output

EDIT: sorry, I forgot to checkout to the dev branch before building. Your changes work on my end. M2 Pro 2023 Sequoia 15.0.0, finnish locale

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.

2 participants