Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4616112
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:56:08+00:00 2026-05-22T01:56:08+00:00

What is the safe/portable way to convert a number to a string (and the

  • 0

What is the safe/portable way to convert a number to a string (and the other way around) ?

I’m on Linux and my settings locale is so that when I use sprintf numbers have a “,” instead of a “.” as a separator.

Sometimes I want them that way, Sometimes not 🙂

I saw some solutions that imply playing with users settings. Clearly that’s something one should not do. Somebody suggested using uselocale

snprintf : simple way to force . as radix?

can someone elaborate a bit (looks like it’s buggy on some glibc (<2.12)) and if possible provide some sample code (eg a macro SNPRINTF_POSIX).

I tried myself but my C skills are very limited.

[edit]

I find this code by [GO]Skywalker13 on Swisslinux.org after writing my question.
Any thoughts about it ? What about memory usage ? (I need to make numerous calls to this func)

#define _GNU_SOURCE
#include <locale.h>
#include <stdlib.h>

double
my_atof (const char *nptr)
{
  double res;
  locale_t new_locale;

  new_locale = newlocale (LC_NUMERIC_MASK, "C", NULL);
  res = strtod_l (nptr, NULL, new_locale);
  freelocale (new_locale);

  return res;
} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:56:09+00:00Added an answer on May 22, 2026 at 1:56 am

    With POSIX 2008, you can use the newlocale and uselocale functions to temporarily change the locale in the current thread without affecting other threads. This is really the only solution, aside from never setting the LC_NUMERIC locale category to begin with. On the other hand, I prefer banning use of LC_NUMERIC in software I write, at least for the global locale. Then you can use newlocale and uselocale locally at the point where you want numeric formatting that matches your user’s cultural conventions, and on systems that lack POSIX 2008 uselocale, simply leave out localized numeric printing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a safe way to use Qt without calling QApplication::exec()? I have a
Is there a safe, portable way to determine (during compile time) the endianness of
Possible Duplicate: Is returning a string literal address from a function safe and portable?
In C++, is it safe/portable to use static member function pointer for C API
Is this portable or at least safe to use with g++? #include <iostream> #include
How safe is it to use Silverlight in production for a graphic form? Is
Is there any safe and standard compliant way to treat a C style array
Is the following code safe? boost::any any_value; { std::string s = HelloWorld; any_value =
EDIT : I believe its safe to say that Flash is finally being discontinued.
How safe is it to use UUID to uniquely identify something (I'm using it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.