|
Actually, you are right. I was answering a different question.
If I had to do what you are attempting to do this is how I would do
it.
Number of decimals = 1
Start at the right most character in the string
Loop1
If it is a number, exit loop
back up one character. If at position 0 exit, no number found
goto loop
Store a variable with the length of my temp variable (say n=15)
Loop2
Move the character into the nth place in my temp variable
Loop3
Back up one character. If at position 0 end loop
If character is a number
subtract 1 from n
if n = 0 exit, number too big
goto loop2
If character is a ',' goto loop3
If character is a '.'
Number of Decimals = Length of Temp Variable - n
goto Loop3
end loop
Number = atof(Temp Variable) / (1 * Number of Decimals)
You get the general idea.
yes, it is a pain. The main reason it is a pain is because 1. You don't
know where in the string the number will occur. 2. You don't know if
the number is going to have .'s or ,'s
Regards,
Jim Langston
Jeff Crosby wrote:
> > > But what if the source string was "12,435"?
>
> I'm sorry, I didn't explain myself well enough (or didn't read your
> original post closely enough to see the positions were hardcoded). What
> I meant was, what if sometimes the commas are there and sometimes not?
> As in "12345" one time and "12,345" the next.
>
> -Jeff
> jlcrosby@fwi.com
> Voice: 219-422-7531 Fax: 219-426-0212
>
> +---
> | This is the Midrange System Mailing List!
> | To submit a new message, send your mail to MIDRANGE-L@midrange.com.
> | To subscribe to this list send email to MIDRANGE-L-SUB@midrange.com.
> | To unsubscribe from this list send email to MIDRANGE-L-UNSUB@midrange.com.
> | Questions should be directed to the list owner/operator: david@midrange.com
> +---
+---
| This is the Midrange System Mailing List!
| To submit a new message, send your mail to MIDRANGE-L@midrange.com.
| To subscribe to this list send email to MIDRANGE-L-SUB@midrange.com.
| To unsubscribe from this list send email to MIDRANGE-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.