Hello every one I am facing a kind of problem in float data type variable in Arduino Uno R3
The float value is taking a value upto only two decimals ,but it's range is beyond that so what should I do now?
Abhay_ras:
The float value is taking a value upto only two decimals ,
No.
You probably only print two of them.
void setup() {
float fVar = 1.23456789;
Serial.begin(250000);
Serial.println(fVar);
for (byte i = 1; i < 10; i++) {
Serial.println(fVar, i);
}
}
void loop() {}
1.23
1.2
1.23
1.235
1.2346
1.23457
1.234568
1.2345678
1.23456788
1.234567880
We can not display a point value upto 10 digit?
You can display as many as you want, but only six to seven are significant.
float
DescriptionDatatype for floating-point numbers, a number that has a decimal point. Floating-point numbers are often used to approximate analog and continuous values because they have greater resolution than integers. Floating-point numbers can be as large as 3.4028235E+38 and as low as -3.4028235E+38. They are stored as 32 bits (4 bytes) of information.
Floats have only 6-7 decimal digits of precision. That means the total number of digits, not the number to the right of the decimal point. Unlike other platforms, where you can get more precision by using a double (e.g. up to 15 digits), on the Arduino, double is the same size as float.
Okay thank you so much !