Skip to content

common: force C locale for numeric formatting#20022

Closed
Scottcjn wants to merge 1 commit intoggml-org:masterfrom
Scottcjn:fix-locale-numeric
Closed

common: force C locale for numeric formatting#20022
Scottcjn wants to merge 1 commit intoggml-org:masterfrom
Scottcjn:fix-locale-numeric

Conversation

@Scottcjn
Copy link
Copy Markdown

@Scottcjn Scottcjn commented Mar 1, 2026

Summary

Ensure consistent decimal point formatting across all llama.cpp tools by forcing LC_NUMERIC to "C" locale.

Problem

On systems with non-English LC_NUMERIC locale (e.g. de_DE.UTF-8), different llama.cpp tools produce inconsistent decimal formatting:

Tool Output Reason
llama-cli 10000,0 (comma) console::init() calls setlocale(LC_ALL, "")
llama-perplexity 10000.0 (period) Default C locale unchanged

This affects all floating-point output including sampler parameters, performance stats, and model metadata — not just GGUF KV data.

Fix

Two-pronged approach:

  1. common_init() in common.cpp: Set LC_NUMERIC to "C" early — catches all tools on startup
  2. console::init() in console.cpp: Override LC_NUMERIC back to "C" after setlocale(LC_ALL, "") — prevents the user locale call from re-overriding the numeric locale

This keeps the user's locale for character handling (UTF-8, wide chars) while forcing consistent period-as-decimal-separator for all numeric output.

Testing

To verify on a system with German locale:

export LC_NUMERIC=de_DE.UTF-8
./llama-cli -m model.gguf -p "test" -n 1 2>&1 | grep -E '[0-9][,\.][0-9]'
# Before: 10000,0 (comma)
# After:  10000.0 (period)

Fixes #10613

🤖 Generated with Claude Code

Ensure consistent decimal point formatting across all tools by
setting LC_NUMERIC to "C" in common_init(). Also override LC_NUMERIC
back to "C" in console::init() after it sets LC_ALL to the user's
locale, preventing locales like de_DE from changing decimal
separators to commas.

Without this fix, tools using console::init() (like llama-cli) print
"10000,0" while others (like llama-perplexity) print "10000.0" on
systems with non-English LC_NUMERIC locale.

Fixes #10613

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Scottcjn Scottcjn requested a review from ggerganov as a code owner March 1, 2026 21:13
@CISC
Copy link
Copy Markdown
Member

CISC commented Mar 1, 2026

Incorrect fix (making a library change global locale) and essentially duplicate of #17331

@CISC CISC closed this Mar 1, 2026
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.

Misc. bug: inconsistent locale for printing GGUF kv data across examples

2 participants