Right left middle string functions in C?

I'm coding something in C and I have a number of variable size up to 3 digits, that I would like to convert to a float. For example, I have 250, I'd like it to show up as 2.50 or if I have 5 I'd like it to show as .05.
What possible ways can I do that? I had thought of sprintf() to make it a string and format it, but I can't figure out how to pull the the numbers to format it with a . in the right spot. atof() ended up with things like 250.00.  Thanks in advance!
LVL 1
GizaAsked:
Who is Participating?
 
jacobhooverConnect With a Mentor Commented:
Hmmm.... assuming you want the decimal always to be in the same spot...

float fBase = atof(szVarSize3);
fBase = fbase/100; // OK, got the "correct number"
char szOut[5];
sprintf(szOut, "%.2f", fBase); // String version of it

0
 
GizaAuthor Commented:
Thanks, that did the trick perfectly!
0
All Courses

From novice to tech pro — start learning today.