The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 localisation, comma as decimal separator
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

northernPat

Germany
2 Posts

Posted - 06/08/2011 :  02:49:30 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 8.5.0 SR1 (E and G)
Operating System: windows xp (german)

Hi Origin Team,
i have a localization problem, i think.

my goal is to put out some important results into the script window or into a note, created by an origin c script using a comma as decimal separator. these results then need to be copied and pasted into various software(including german excel) recognizing only comma as dec. separator..

the main problem now is that i can't get origin to print a comma instead of the standard decimal period. using printf() or others..

i tried setting the C locale using setlocale() and including the locale.h - seemingly there is no locale.h...:(

is there any possibility of getting an elegant solution for this ?

many thanks in advance.

best regards from northern germany,
patrick

Penn

China
644 Posts

Posted - 06/08/2011 :  10:23:21 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi patrick,

Before you put out the results to the script window, you can first convert these results to strings. For example:

void test_decimal_separator()
{
	double aa = 1.253;
	string str = ftoa(aa);  // convert the numeric to string
	printf("aa = %s\n", str);
}


Penn
Go to Top of Page

northernPat

Germany
2 Posts

Posted - 06/09/2011 :  05:05:03 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
many thanks, didn't really think about that :)

it's not really the cleanest as it spawns new problems..
i have to round manually before converting to string - thats ok.

but then: i have no control over the decimal point in a string anymore..
and as i can get any sort of value e.g. -4,23 or even 1243,56 printf truncates the string after a given length irrespective of a sign or a large or small floor.

or am i missing something ?

EDIT:

i found a solution using the magic sprintf, i'll just post it in case someone else has a problem with the decimal separator, which is always a big hassle here...
string wobble(double x)
{
	// take double, let sprintf round and replace period by comma
	// return the string
	int i =0;
	char safe[16];
	
	sprintf(safe,"%.2f",x);
	
	for(i;i<16;i++)
	{
		if(safe[i] == '.')
			safe[i] = ',';
		if(safe[i] == '\0')
			break;
	}
	return safe;
}


Edited by - northernPat on 06/09/2011 07:15:18 AM
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 06/12/2011 :  08:24:20 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Penn's solution is fine, as ftoa has similar format control as printf. In addition, ftoa allows Labtalk's more flexible format control, so for example, to print with 2 decimal, you use



void dd(double aa = 1.253)
{
  string str = ftoa(aa, ".2");  //LT format of 2 decimal
  printf("aa = %s\n", str);
}




You can refer to this link for the LabTalk formatting notation:

http://wiki.originlab.com/~originla/ltwiki/index.php?title=LabTalk:Substitution_Notation#.24.28_.29_Substitution

CP
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000