Friday, February 17, 2006

ToString formating

this should be a basic C++ knowledge, but looks like it's easy to be forgotten. And even worse, hard to find it online since it's so basic.

if you have integer like 4,6,11. but you want to convert to string like "04","06","11", --- padding a "0" on the left if it's single digit.
then you should use this:

number.ToString("d2") // d means to decimal, where 2 means 2 digits format