I have a number for example: 2.4444444. I need to get first digit after the dot -- in my case it's 4. How to implement it?
How about
( (int)(floor( fabs( num ) * 10 ) ) ) % 10
Chech these out! Tried it for you hope it helps
#include<stdio.h>
int main()
{
int b;
float a;
a=2.4444; // Load some value
b=(int)a; // Typecast it into integer you get 2 into b variable
a=a-b; // Subtract b from a and you will get decimal point value 0.4444
a=a*10; // Multiplying with 10 gives 4.444
b=(int)a; // Now apply the same logic again
printf("%d",b); // Outputs 4
}
Update written these function using these link
How to extract the decimal part from a floating point number in C?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With