You could simulate the digits text with a str_printf call, and then use str_width the get the pixel-precise width of that text.