Manipulating decimal numbers in ‘C’
In this article, let’s understand Manipulating decimal numbers in ‘C.’ Let’s explore.
Representation of decimal numbers in āCā
- A Decimal Number contains a Decimal Point.
- For example, 125.55 is a decimal number(a real number).
- In computer memory, the real numbers are stored according to the representation standardization by the IEEE standard 754.
- IEEE754 floating-point representation is an approximate representation of real numbers.
- All computer systems and microcontrollers nowadays use this standard to store real numbers in memory.
- If you are working with numbers that have a fractional part or in case you are using integers that don’t fit into a long data type, then we can use floating-point representation.
So, we have discussed about integer data types. Those data are not stored according to this standard remember.
Let’s consider a number that is too small in nature. For example, the charge of an electron.
How do you represent this in your ‘C’ program?
You cannot use integer data types. So, you have to use floating-point data types, which are called float and double in ‘C.’ So, we will explore that in a moment.
Let’s consider a very big real number. Let’s say the distance between Earth and Andromeda galaxy. It’s a very big number. So, you cannot fit this data by using an integer data type like long long because it’s a very big number. That’s why remember that in ‘C,’ too small or too big numbers or numbers having a fractional part are represented using floating-point representation data types such as float and double.
In summary, why do we need floating-point representation?
- To store, a too-small number in memory,
- To store, a too big number in memory,
- To store a number which has a fractional part, or we can also call it a decimal number.
In the following article, let’s explore the IEEE-754 floating-point standard to store floating-point numbers.
FastBit Embedded Brain Academy Courses
Click here: https://fastbitlab.com/course1