Skip to content

Conversation

@Pana1v
Copy link
Contributor

@Pana1v Pana1v commented Dec 25, 2025

Replace std::stod() with locale-independent std::from_chars() to ensure decimal numbers are parsed correctly regardless of system locale settings.

Fixes #1237

panav and others added 2 commits December 25, 2025 14:01
Replace std::stod() with locale-independent std::from_chars()
to ensure decimal numbers are parsed correctly regardless of
system locale settings.

Fixes facontidavide#1237
@facontidavide
Copy link
Owner

doesn't compile for macos!

@facontidavide
Copy link
Owner

I found a different solution using Qt provided function, that I think is better for portability.

FYI:

std::optional<double> toDouble(const std::string& str)
{
  // If comma is used as decimal separator (European format), replace with dot
  QString qstr = QString::fromStdString(str);
  qstr.replace(',', '.');

  // Use QLocale::c() for locale-independent parsing (always uses '.' as decimal separator)
  bool ok = false;
  double value = QLocale::c().toDouble(qstr, &ok);
  return ok ? std::optional<double>(value) : std::nullopt;
}

thanks a lot anyway for looking into this

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.

[BUG]: Decimal separator not detected properly

2 participants