How to use $sprintf - with field width and not padding

In reply to snognogt:

You have to Modify your formatter like this

$sformatf("0x%0h", my_number)

%0h prints only the numbers really needed.