logo

Reasons for Using the Format Codes d and f for Integers and Floating-Point Numbers 📂Programing

Reasons for Using the Format Codes d and f for Integers and Floating-Point Numbers

Why Specifically d and f

20180409\_152729.png 1

In programming languages like C or Python, format codes used for string input/output include %s, %c, %d, %f, etc. As known, %s represents a string, and %c represents a character. However, unlike these taking the first letter of their meaning, for integers and floats, it’s not %i or %r but %d and %f.

The reason is that %d is not just any integer but specifically signifies a decimal, and %f represents a floating-point number. Similarly, remember that octal and hexadecimal are represented by %o and %x, respectively.