The number zero is the number zero no matter how it’s written. The program can’t memorize how it was originally written in the source code because the string "0000" doesn’t even exist at runtime.

As another example: println!("{}", 2 - 2); shall print 0, and not 2 - 2. It is very important to distinguish the representation of a number / quantity with the quantity / value itself. You can use multiple representations for the "null quantity", such as 0, 0000, 2 - 2 (this one is technically (the representation of) a computation, but that can be viewed as a representation as well (e.g., how are fractions (such as 1/3) represented, if not as a division?)), 0b0 (binary representation), 0x0 (hex representation). Be it as it may, the machine will end up with a value, represented / stored in its own machine format (e.g., 0b0000_0000__0000_0000__0000_0000__0000_0000_i32 in your case), and that value has a canonical representation, which the {}-Display (and {:?}-Debug) implementation uses, and in this instance such representation can even be tweaked. If you want 4-wide representations, using 0 to pad it, you can use {:04} (or {:04?}).

I mean I appreciate the fact that you haven't missed any closing parentheses, but when reading this I almost assumed you did untill I reached the final “))”

You've gotten some great answers. I'd also add that there often values that look numerical but are better represented as strings. The fact that you care about the number of leading zeros suggests this might be your case. Phone numbers, and probably zipcodes are good examples.

My social security number begins with a 0. In the early days of computerizing stuff (I'm really old.), I often got an "Invalid SSN" error for exactly the reason pointed out here. It's a string, not 3 numbers.

The important question is: "Are you doing math on it?"

If the answer is no, as in the case of SSN's, phone numbers, zip codes, and id numbers of most kinds, then what you really want is a string, not a number. A good example is when those zip codes are expanded to postal codes outside the U.S. and you find that letters are used.