Hi-

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.

Thanks for any help,
Steve

Re: using % to get 2 digit year by Igor

Igor
Thu Apr 22 16:04:24 CDT 2004

"sklett" <stevek@spamfree.net> wrote in message
news:e2uE1xKKEHA.1764@TK2MSFTNGP12.phx.gbl
> 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;

You probably want

WORD shortYear = longYear%100;

1990%2000 == 1990, but 1990%100 == 90

> the result is always 4 instead of the desired 04

You got a number, not a string. It is meaningless to say that a number
has or does not have leading zeros. When you convert it to a string or
format it for printing, that's when you can add leading zeros.
--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken



Re: using % to get 2 digit year by Tim

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/



Re: using % to get 2 digit year by sklett

sklett
Thu Apr 22 19:05:50 CDT 2004

of course. I was trying to use SetDlgItemInt(), a quick format to string
and I am good to go using AddString()

Thanks and sorry for the pretty dumb question.



"Igor Tandetnik" <itandetnik@mvps.org> wrote in message
news:Oj1Jl1KKEHA.3304@TK2MSFTNGP10.phx.gbl...
> "sklett" <stevek@spamfree.net> wrote in message
> news:e2uE1xKKEHA.1764@TK2MSFTNGP12.phx.gbl
> > 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;
>
> You probably want
>
> WORD shortYear = longYear%100;
>
> 1990%2000 == 1990, but 1990%100 == 90
>
> > the result is always 4 instead of the desired 04
>
> You got a number, not a string. It is meaningless to say that a number
> has or does not have leading zeros. When you convert it to a string or
> format it for printing, that's when you can add leading zeros.
> --
> With best wishes,
> Igor Tandetnik
>
> "For every complex problem, there is a solution that is simple, neat,
> and wrong." H.L. Mencken
>
>