Truncating integer

Discussion in 'C++' started by VonTöppel, Jun 28, 2008.

  1. VonTöppel

    VonTöppel Guest

    Hi!
    Is there a simple way to drop numbers from integer value with string
    formatting? Here's my problem:

    int year = 2008;
    printf("%02d", year);

    It now prints "2008", but I would like it to print just "08". I could
    subtract 2000 from the orginal value but I was wondering whether there's
    another, more beutiful way to solve this.
    VonTöppel, Jun 28, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jitesh Sinha
    Replies:
    1
    Views:
    619
    Munsifali Rashid
    Dec 5, 2003
  2. Jason Williard

    Truncating Variables

    Jason Williard, Oct 15, 2004, in forum: ASP .Net
    Replies:
    11
    Views:
    5,335
    Kevin Spencer
    Oct 18, 2004
  3. uy_do
    Replies:
    1
    Views:
    665
    Harish Madhavan
    Dec 4, 2003
  4. BemusedByQM

    truncating java 'doubles'

    BemusedByQM, Jul 24, 2005, in forum: Java
    Replies:
    2
    Views:
    17,406
    jfalt
    Jul 25, 2005
  5. qazmlp

    Truncating char array

    qazmlp, Jul 25, 2003, in forum: C Programming
    Replies:
    4
    Views:
    400
    Richard Bos
    Jul 28, 2003
Loading...

Share This Page