I have extracted a number with a decimal place from a string using strtok
, 1,2,1.0
.
UPDATE
The format in this case will be limited from 0.0 up to 1.0
. So a single primary & decimal place. The printf is for user feedback & confirmation, the number is passed to a library that requests a number format
of n.n
. Perhapse I am misinterpreting the message and as a c program only reuires .n
if the number is less than one.
I now need to convert the third number to an int with a n.n
format that requires a leading zero if less than one.
I have tried a few combinations of int, float, double
and atoi(x), strtoumax
, but get either 1
or 1.0000....
in the printf.
I need to printf and use the var internally. So what would be the best combination and format to use?
// third number (this may move position in token order)
????? myNumber;
strcpy(string, strtok( NULL, ","));
myNumber=atoi(string);
printf("the number is %?\n", myNumber);
g_object_set(theItem, "alpha", myNumber, NULL); // accepts n.n only 0.0 -> 1.0