|
-
May 17th, 1999, 09:42 PM
#1
how to display one digit integer to two or more digit
I want to display one digit integer to two or more digit.For example,m_hour=1.I want to display '01'.But I don't use complex method.(eg. at first judge the digit of the integer.Then to decide whether add 0 to the number).
Have you some good methods?Please teach me.
Thank you all.
-
May 17th, 1999, 09:44 PM
#2
Re: how to display one digit integer to two or more digit
uhhhh... i think if you include "iomanip.h" and use setprecision(x) in your output statement it would format it to whatever(only for console programming).
#include <iomanip.h>
...
...
cout << setprecision(2) << x << endl; // if x==2, outputs '02' ... i think
-
May 17th, 1999, 10:08 PM
#3
Re: how to display one digit integer to two or more digit
-
May 18th, 1999, 02:19 AM
#4
Re: how to display one digit integer to two or more digit
You could use the CString's Format member function:
CString sFormattedString;
// automatically adds leading zero if m_hour is < 10
sFormattedString.Format("%02d",m_hour);
-
May 29th, 1999, 05:52 PM
#5
Re: how to display one digit integer to two or more digit
use wsprintf(). Is just like printf (you must know printf!, don't you?).
char outstr[3];
wsprintf(outstr,"%02d",my_integer);
and if you want it in a CString just write:
CString MyString(outstr);
Then do the output of the string outstr or MyString as you like.
Again, if you don't understand the "%02d" stuff get a basic C programming book and look for printf's format specifiers.
-
May 30th, 1999, 02:54 AM
#6
Re: how to display one digit integer to two or more digit
better to go:
CString str;
str.Format( "%02d", m_int );
the previous will crash if m_int is larger than 99
Sally
-
May 30th, 1999, 01:38 PM
#7
Re: how to display one digit integer to two or more digit
A "one digit integer" (as jinglei asked) is hardly avobe 99. Besides i was only suggesting to him to use printf's format specifiers.
-
May 30th, 1999, 07:21 PM
#8
Re: how to display one digit integer to two or more digit
you never know how source code will develop.....
I find it a good programming practice to cater for the unforseen
Sally
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|