It should be noted that int always rounds down, while sprintf will flexibly round the proper direction. I didn't notice which way the OP wanted, nor whether the distinction would matter in the particular case. It's a good issue of which to be aware, though.