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
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 localisation, comma as decimal separator

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
northernPat Posted - 06/08/2011 : 02:49:30 AM
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
3   L A T E S T    R E P L I E S    (Newest First)
cpyang Posted - 06/12/2011 : 08:24:20 AM
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
northernPat Posted - 06/09/2011 : 05:05:03 AM
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;
}

Penn Posted - 06/08/2011 : 10:23:21 PM
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

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000