solaris appl migration: sprintf decimal separator

Hi,

I am trying to migrate an application from Solaris to AIX 5.3.1. In both platforms the locale settings are as follows:

Result of executing "locale"
LANG=C
LC_CTYPE="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_COLLATE="C"
LC_MONETARY="C"
LC_MESSAGES="C"

In solaris when you execute this program (this is a sample, in the original code there are lots of classes but at the end they call sprintf function to fill a char[] variable):

#include <string.h>
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char * argv[])
{
    char cadena[25];
    double a = 0;

    memset(cadena,0,sizeof(cadena));

    sprintf(cadena, "%-f", a);
    printf("The content is : %s\n", cadena);
}

In AIX I am compiling this code (main.cpp) with:

IBM XL C/C++ Enterprise Edition for AIX, V9.0
Version: 09.00.0000.0007

In solaris the output is :

0,000000 -> with a comma separator

But in AIX when I try to execute this, the result is:

0.000000 -> with a point separator

I am trying to migrate the code having in mind the idea of not touching the original code. Any idea?,

Thank you in advance for your attention and time.
David

It looks like the LC_NUMERIC definition for the radix character is different. localedef allows you to customize any part of a locale definition. Or the entire definition.

Why things are that way I do not know. But the AIX setting is actually correct for the POSIX (C) locale. The Solaris setting is not standard.

See this on how to change the locale setting. BE SURE to check with the users/management on the new box before you change locale settings!

Help -

Jim,

Thank you for your help. We have defined a small locale only with numeric information. After that I have developed a header that it is used by the original program in order to include and execute the appropiate setlocale function and then include the original one.

David

I notice that you do not mention LC_ALL. What is it set to?

Note that the value of the LC_ALL environment variable has precedence over any of the other environment variables starting with LC_ (LC_COLLATE, LC_CTYPE, LC_MESSAGES, LC_MONETARY, LC_NUMERIC, LC_TIME) and the LANG environment variable.

Hi,

LC_ALL is set to nothing. When i execute locale into a shell I receive all params with its correpsonding value except this one that doesn't have any value assigned.

David

Set LC_ALL to the C locale and see what happens in your example program.