|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
* VonTöppel:
> 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. How about "year % 100"? Cheers, & hth., - Alf -- A: Because it messes up the order in which people normally read text. Q: Why is it such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail? |
|
![]() |
| Outils de la discussion | |
|
|