float Single-precision floating-point type

float Single-precision floating-point type

float is single-precision, often 32-bit IEEE 754, not mandated. f suffix avoids double; approximation makes == unreliable, and varargs promote to double.

CategoryType specifiers
KindKeyword / Statement
C standardC89 / C90

📝 Syntax

float f = 3.14f;

▶ Example

Edit the C code below and click Run; the server compiles and executes it:

Output:

ratio = 0.25

📚 Related Tutorials

❓ FAQ

QHow do the types of 3.14 and 3.14f differ?
A3.14 has type double, while 3.14f has type float. Assigning the double literal to float requires another conversion, so an explicit f suffix avoids the unnecessary type difference.
QCan == be used to compare floating-point results for equality?
AMany decimal fractions have no exact binary floating-point representation, and rounding can give different values to mathematically equal expressions. Design comparisons around the problem's scale and error bounds; a small fixed epsilon is not universally suitable.
QCan printf's %f print a float directly?
AYes. A float passed as a variadic argument is promoted to double, which is exactly what %f expects. With scanf, use %f for a pointer to float and %lf for a pointer to double.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏