Leading zero


A leading zero is any 0 digit that comes before the first nonzero digit in a number string in positional notation. For example, James Bond's famous identifier, 007, has two leading zeros. When leading zeros occupy the most significant digits of an integer, they could be left blank or omitted for the same numeric value. Therefore, the usual decimal notation of integers does not use leading zeros except for the zero itself, which would be denoted as an empty string otherwise. However, in decimal fractions strictly between −1 and 1, the leading zeros digits between the decimal point and the first nonzero digit are necessary for conveying the magnitude of a number and cannot be omitted, while trailing zeros – zeros occurring after the decimal point and after the last nonzero digit – can be omitted without changing the meaning.

Occurrence

Often, leading zeros are found on non-electronic digital displays or on such electronic ones as seven-segment displays, that contain fixed sets of digits. These devices include manual counters, stopwatches, odometers, and digital clocks. Leading zeros are also generated by many older computer programs when creating values to assign to new records, accounts and other files, and as such are likely to be used by utility billing systems, human resources information systems and government databases. Many digital cameras and other electronic media recording devices use leading zeros when creating and saving new files to make names of the equal length.
Leading zeros also present whenever the number of digits is technically fixed, but the stored value is not large enough to result in a non-zero most significant digit. The count leading zeros operation efficiently determines the number of leading zero bits in a machine word.
A leading zero appears in roulette in the United States, where "00" is distinct from "0". Sports where competitors are numbered follow this as well; a stock car numbered "07" would be considered distinct from one numbered "7". Benito Santiago, a Major League Baseball catcher who wore the number 09 for several years, is the only major professional sports league player to use a jersey number with a leading zero, not counting several who have worn the number 00. This is most common with single-digit numbers.

Advantages

;Collation
Leading zeros are used to make ascending order of numbers correspond with alphabetical order: e.g., 11 comes alphabetically before 2, but after 02. This does not work with negative numbers, though, whether leading zeros are used or not: −23 comes alphabetically after −01, −1, and −22, although it is less than all of them.
; Error prevention
Leading zeros in a sentence also make it less likely that a careless reader will overlook the decimal point. For example, in modern pharmacy there is a widely followed convention that leading zeros must not be omitted from any dose or dosage value in drug prescribing. Likewise, just as leading zeros are mandatory, trailing zeros are forbidden. In both cases, the reason is the same: to prevent misreading and the resultant misdose by one or several orders of magnitude.
; Fraud prevention
Leading zeros can also be used to prevent fraud by filling in character positions that might normally be empty. For example, adding leading zeros to the amount of a check makes it more difficult for fraudsters to alter the amount of the check before presenting it for payment.

Zero as a prefix

A prefix 0 is used in C to specify string representations of octal numbers, as required by the ANSI C standard for the "strtol" function in the "stdlib.h" library. Many other programming languages, such as Python 2, Perl, Ruby, PHP, and the Unix shell bash also follow this specification for converting strings to numbers. As an example, "0020" does not represent 2010, but rather 208 = 1610. Decimal numbers written with leading zeros will be interpreted as octal by languages that follow this convention and will generate errors if they contain "8" or "9", since these digits do not exist in octal. This behavior can be quite a nuisance when working with sequences of strings with embedded, zero-padded decimal numbers to facilitate alphabetical sorting or when validating inputs from users who would not know that adding a leading zero triggers this base conversion.