float with large decimal values becomes zero, how to read all decimal values?

float B = 3950;
void setup() { }
void main()
{
float bee = 1 /B;
Serial.println(bee);
}

using calculator I got bee value as 2.53164557e-04
but while compiling the code "bee" value becomes zero. Why?

tried to specify the decimal value in Serial.println and it works > Serial.println(bee,6);

but if there is one more equation say, "float alpha = 500 * bee;" and not printing it in Serial.println, the value becomes zero.

how to read all decimal values?

I get .000253

Probably not the math but the print statement rounding it off.

-jim lee

it works > Serial.println(bee,6);

Problem solved.

jimLee:
I get .000253

Probably not the math but the print statement rounding it off.

-jim lee


Yeah, just noticed it, sorry and thanks. I changed the value but the problem is still there.

https://forum.arduino.cc/index.php?topic=687073.0

Check this topic, and you'll understand why i asked.

rd369:

Yeah, just noticed it, sorry and thanks. I changed the value but the problem is still there.

thermistor value to servo motor, not getting value - Programming Questions - Arduino Forum

Check this topic, and you'll understand why i asked.

int roomTemp = 28+273.15; // Room Temperature (Kelvins)
float sum = (1/roomTemp) + productTerm; // 1/T0 + 1/Bln(r1/r0)

Since 'roomTemp' is an integer and greater than 1, the sub-expression "(1/roomTemp)" is going to be zero.

As a best practice, I only use floats in float expressions, since mixing ints and floats sometimes gives unexpected results (truncation errors). Perfect example is the thread you linked.

instead of

float bee = 1 /B;

I'd write

float bee = 1. /B;

rd369:
tried to specify the decimal value in Serial.println and it works > Serial.println(bee,6);

but if there is one more equation say, "float alpha = 500 * bee;" and not printing it in Serial.println, the value becomes zero.

Can you provide an Arduino sketch that demonstrates the problem?