Floating Point Literals

Floating Point Literals

In following expression:

   if (ticket_price > 7.50)

What’s the type of the literal 7.50? One might think that it’s float. However, the actual type is double. To force the compiler to store a floating point literal as a float rather than double, you have to append the affix ‘f’ to it:

   if (ticket_price > 7.50f)

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist