+ 4
For decimal values we use which datatype.
Every datatype consist of different type of values like int holds integer values.
15 Antworten
+ 2
You can use float or double
+ 6
Float
+ 5
Float
+ 2
float using for decimal numbers
+ 1
Don't forget to add f for floating values because either they are initialised with float data type but measured as double.
int x = 4;. // result 4
float y = 5.6; ❌
// result 5.6 (but initialised as double)
float y = 5.6f; // f is needed here.✔️
double z = 8.9;
// Initialized as double correctly.
Check that by
sizeof(variableName);
difference b/w float and double
float has 7 point precision
means
float x = 5.123456789f;
cout << x; // result 5.1234567
double has more precise (more accurate) than float
means
double y = 5.1234567890;
cout << y; // result 5.1234567890
+ 1
For decimal : use float
+ 1
You can use float or double
For example;
float x=2.4;
double x=665.678923333;
+ 1
*Nitrocell
I think double always store values as decimal.
By your definition we can store integers in float also.
double => N.N always
Have a nice day. 👍
0
Float or double for decimal values
0
Piyush Pranjal 🇮🇳 hey bud, I've mastered C, and C++. I know what I am saying. I read books and from C and C++
float => N.N
int => N
double => N or N.N
0
*Nitrocell
Aren't those the same? I mean by definition floating-point, which are both float and double, has the ability to represent real number, or decimal (decimal is actually the wrong term since decimal is a number radix). Mathematically, every integer is real number, so I think something like integer and real number is redundant, and there's no "real number only" since every possible numbers is real number, unless of course something like imaginary number is added to the group
0
Dharmendra Kumar
0
Piyush Pranjal 🇮🇳 Agent_I guys I know and understand that all. I only want to make example, that will be easy to understand for beginners and others. I learnt that float can store value only with decimal(N.N) number. Int can store integer, and must be without POINT(.). Double can store both of them. So double's value can be N.N or N or N.NNNN.
Good luck with coding guys. 👍
- 1
float and double
float - only decimal value
double - decimal and integer
- 1
*Nitrocell
What ????
Do u know what you're telling.... 🤔🤔🤔