Tuesday, August 18, 2009

Life Expectancy

I booked a train ticket for my mother using IRCTC. I was quite (pleasantly) surprised to find the age printed in 3 digits in the Electronic Reservation Slip:

I find the zero-padding a bit geeky. The Right Way, IMO, would've been just printing it in 2 or 3 digits depending on the value.


It'd be utterly ungrateful if I didn't mention the nice tool I used to grab the above screenshot. It's called Shutter. It's one amazing tool (despite being GNOME!) for quickly creating screenshots. Almost everything you need to do with the grabbed image (adding arrows and text, masking sensitive info etc. etc.) can be done within the same application! Isn't that wonderful? Just that the UI is not all that intuitive :-(

A quick piece of info you already knew: the following C code prints the value with zero padding:
printf("%03d\n", 54);

With cout/C++, the same effect can be achieved with the ugly:
cout << setfill('0') << setw(3) << 54 << endl;

This formatting convenience of printf is perhaps the only 'C' thing I prefer over C++!

No comments:

Post a Comment