Unwanted commas in text formated by Glib::ustring::format (Gtk4)

Any clues to why large numbers formatted via Glib::ustring::format() would contain commas at the thousands and millions places? A simple stand-alone program doesn’t show them (both Gtk3 and Gtk4) but they are showing up in the Gtk4 port of Inkscape so something is enabling them but I can’t figure out what.

What locale are you running Inkscape vs the test program in, and does the test program call setlocale (LC_ALL, "") to load the locale from the environment?

This outputs “1,000,000” on my system in my default locale. When run the program with LC_NUMERIC=C it outputs 1000000.

#include <iostream>
#include <glibmm.h>

int main() {
    std::locale::global(std::locale(""));
    std::cout << Glib::ustring::format(1000000) << '\n';
    return 0;
}

Thanks for the reply.

After further testing and investigation, I think I’ve figured this out. In Gtkmm4, the C++ locale is explicitly set to match the C locale with std::local::global(). This was not done in Gtkmm3. See Bug 661588 – Set the global locale in Glib::init() .)

My test program wasn’t testing the correct things. I tried using std::setlocale() which only effects ‘C’ functions like printf (switching the decimal point to a comma, for example with fr_FR.UTF-8). And I wasn’t initializing Glibmm or Gtkmm (via Glib::init() or Gtk;;Application::create()) which would change the C++ locale. Glib::ustring::format() uses std::ostringstream or std::wostringstream under-the-hood which are effected by the C++ locale.

I did try setlocale() but it turns out that doesn’t change the “C++” locale which Glib::ustring::format() depends on through its use of std::ostringstream or std::wostringstream.

Thanks for the reply.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.