This should be simple, but I'y stymied on it.
int interval=998000;
Frequency = ((float) 1000000/(float) interval);
Serial.print(Frequency);
Serial.println(" Hz")
The output is "1.00 Hz" Why am I only getting 2 decimal points here?
This should be simple, but I'y stymied on it.
int interval=998000;
Frequency = ((float) 1000000/(float) interval);
Serial.print(Frequency);
Serial.println(" Hz")
The output is "1.00 Hz" Why am I only getting 2 decimal points here?
Because you didn't ask for any more.
int interval=998000;What is the largest number that a signed int can hold ?
AWOL:
Because you didn't ask for any more.
When printing the value, that is.
UKHeliBob:
int interval=998000;What is the largest number that a signed int can hold ?
It depends on the platform.
ltetzner:
This should be simple, but I'y stymied on it.int interval=998000;
Frequency = ((float) 1000000/(float) interval);
Serial.print(Frequency);
Serial.println(" Hz")
The output is "1.00 Hz" Why am I only getting 2 decimal points here?
an int can only hold up to 32767, so interval should be an (unsigned) long or better as you are casting it to float make it a float.
Note that floats have only 7 significant digits in Arduino UNO land.
float interval=9.98e5;
Frequency = 1e6/ interval;
Serial.print(Frequency, 4); // 4 decimals
Serial.println(" Hz")
AWOL:
UKHeliBob:
int interval=998000;What is the largest number that a signed int can hold ?It depends on the platform.
True. But I am sure that you knew what I meant !
I did, but there was a clue that 1000000/ 14960 is nowhere 1. ![]()