Tim
Thu Apr 22 16:16:37 CDT 2004
sklett wrote:
> I'm trying to use the mod operator to convert a 4 digit year to a 2
> digit one. Here is what I'm doing:
>
> WORD shortYear = 2004%2000;
>
> the result is always 4 instead of the desired 04
> I don't even know where to begin with this one. I googled pretty
> hard, but didn't find anything informative.
4 is the same thing as 04. (It's also the same as 004, 0004, etc.)
If you want to output the value of shortYear with one leading zero (i.e. 4
becomes 04), you'll have to look up how to do that with whatever output
function you're using.
For example:
WORD shortYear = 2004 % 2000;
printf("shortYear = %d = %02d\n", shortYear, shortYear);
prints:
shortYear = 4 = 04
--
Tim Robinson (MVP, Windows SDK)
http://mobius.sourceforge.net/