Re: text to number 2
- Posted by Irv Mullins <irvm at ellijay.com> Jan 30, 2002
- 461 views
dmc wrote: > ok, I have reviewed the value library function for converting a > sequence to a number, but how do you get a sequence like > {"-","1","2",".","2"} to be {"-12.2"} as the function needs it to be? > Or am I missing something obvious? I need to make a file filter and I > need to be able to convert back and forth regularly from string to > numeric. The question no one has asked is: How are you getting that strange sequence in the first place? You mention file filters, so I'm guessing you're reading them from files. If so, you're just going about that in the wrong way. If the files are pure numeric, then get() should work, no conversion necessary. If the files are mixed text and numbers, then you can either slice the numbers out, i.e. line[12..16] if they are column-aligned, or if the numbers appear in random places within a line, use gets() to read in the line, and then parse the number(s) out with strtok.s, then convert with value() A sample of the input data would help. Regards, Irv