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
 Trim 0 and . from string

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
peter.cook Posted - 02/12/2004 : 10:18:37 AM
Hi,

Can anyone help with :

I have a number as text from which I want to trim any right zeroes only if there is a decimal point but also decimal point if it is left eg

12.345 : 12.345
12.300 : 12.3
12.000 : 12
0.0010 : 0.001
123000 : 123000

Can anyone suggest slickest/quickest way thanks?

I've tried using .TrimRight('.') and .TrimRight('0') but I think I need to see there is a '.' in the string first..?

Cheers,

Pete


3   L A T E S T    R E P L I E S    (Newest First)
cpyang Posted - 02/12/2004 : 12:58:13 PM
Sorry, you are right, default will be to convert to scientific notation at 1E-3, so the following code will do


void test(string strVal = "0.0010")
{
double dSLsave;
LT_get_var("@SL", &dSLsave);
LT_set_var("@SL", -6); // set Oriign's internal convert to scientific notation to 1E-6
double val = atof(strVal);
char szTemp[30];
DoubleToStr(val, szTemp, 30, "*");
LT_set_var("@SL", dSLsave); // restore after convert
out_str(szTemp);
}



CP


Edited by - cpyang on 02/12/2004 1:12:16 PM
peter.cook Posted - 02/12/2004 : 12:30:14 PM
Hi CP,

I think the above returns eg 1e-3 whereas I actually want to see 0.001 as text as described.

Cheers,

Pete

cpyang Posted - 02/12/2004 : 12:17:41 PM
Simplest would be to use Origin's internal code which is used in LabTalk,

1. convert string into double
2. call DoubleToString to convert,
example



string str = "0.0010";
double val = atof(str);
char szTemp[30];
DoubleToStr(val, szTemp, 30, "*");
out_str(szTemp);



CP





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