Extracting decimal number from string
ankit7540
I am trying with sscanf command :
<br />
printf "Location error for peak: %g is : %s \r", peaknumber, ErrorString<br />
variable FPError<br />
sscanf ErrorString , "%e" , FPError<br />
printf "Location error in number : %g \r", FPError<br />
<br />
// ErrorString = string value in error example +/- 0.018739<br />
// FPError = numeric value for error<br />
<br />
printf "Location error for peak: %g is : %s \r", peaknumber, ErrorString<br />
variable FPError<br />
sscanf ErrorString , "%e" , FPError<br />
printf "Location error in number : %g \r", FPError<br />
<br />
// ErrorString = string value in error example +/- 0.018739<br />
// FPError = numeric value for error<br />
<br />
I have tried with %d , %u tags but it didn't work. Always the numeric variable has zero value (indicating it is taking only the value before the decimal).
Should I try SplitString command.
Using
sscanf
with a format expression does the job.sscanf Errorstring, formatString , v1, FPError
:-)
March 14, 2015 at 02:52 am - Permalink