Zero padding

Hi i want a C program to convert 2.3 to 0002.3.Please give me any idae.Any in built function is there for this conversion?
That isn't a conversion, it's a display format issue. The numbers are the same.
K.How to change the format?.I tryed with swprintf but not working
No.Its not working Itryed that one already.Actually the problem with _wtof().
code:

1
2
3
TCHAR *pBuf={"A2.3"};
float f=_wtof(pBuf++);
printf("%06.1f",f)

Output should be
A0002.3
Last edited on
A2.3 is a string. Why aren't you trying to format the number 2.3?

Did you bother to look at the value of f?
Last edited on
I thought first i convert that string to float no:and format the float no: and append with A.But i am not getting the format 2.3 to 0002.3._wtof function failure is the problem.What may be the reason of _wtof failure.
Last edited on
What is TCHAR? What is _wtof? Parameter type, return type? Does it provide any error handling?

If you do have a cstring, then you can measure its length and find the position of the dot. It is then possible to construct a new cstring with appropriate number of "0" characters in front. Converting string->float->string is not so nice due to the nature of floats.
Its working now
1
2
3
TCHAR *pBuf={"A2.3"};
float f=_wtof(++pBuf);
printf("%05.1f",f) 
Good, but could you explain what do you think to be the reason why "it is working" now?
It works because he's (erroneously) incrementing pBuf to step past the "A" and point to "2.3".
Topic archived. No new replies allowed.