- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How floats are stored in C compiler?
In C programming language, float is a short term for floating point.
Floating point numbers are generally represented in the form of Institute of Electrical and Electronics Engineers (IEEE) format.
The IEEE format uses a sign bit, a mantissa and an exponent for representing the power of 2.
The sign bit denotes the sign of the number: a 0 represents a positive value and a 1 denotes a negative value.
The mantissa represented in binary after converting into its normalized form. After normalization mantissa, the most significant digit is always 1.
The exponent is an integer stored in unsigned binary format after adding a positive integer bias.
This ensures that the stored exponent is always positive.
For float, the bias is 127 and for doubles, the bias is 1023.
Example
Following is the C program for rounding the floating point number to four decimal places in C language −
#include <stdio.h> int main(){ float var = 37.66666; printf("%.4f", var);// rounding to four decimal points return 0; }
Output
When the above program is executed, it produces the following result −
37.6667
Following is the C program for rounding floating point number to eight decimal places in C language −
Program
#include <stdio.h> int main(){ float var = 78.67; printf("%.8f", var); return 0; }
Output
When the above program is executed, it produces the following result −
78.66999817
- Related Articles
- How do I generate random floats in C++?
- Where are static variables stored in C/C++?
- How to Install C++ Compiler on Windows?
- How to Install C++ Compiler on Linux?
- How is JIT compiler different from normal compiler?
- How to install c c compiler and development tools in ubuntu
- What are Parsing Techniques in Compiler Design?
- What are Precedence Functions in compiler design?
- How Java objects are stored in memory?
- How are Java objects stored in memory?
- How to add “graphics.h” C/C++ library to gcc compiler in Linux
- Why is f required while declaring floats in C#?
- Builtin functions of GCC compiler in C++
- What are stored procedures? How to call stored procedures using JDBC program?
- What are the attributes of programming languages in compiler design?
