Loosing decimals in a float multiplication

Hello everyone!

I have written a small code to test multiplying floats and longs and I am loosing the decimals. The solution to this calculation should be 8388607.161. I am thinking that this might have something to do with the size of the multiplication, since a float can't have this many decimals and integers? If this was to be the problem what solution could it have? Here is the code that I am using with my Arduino nano:

void setup() {


void loop() {

  unsigned long   refFrequency = 20000000.0; 
  unsigned long   quartzCount = 4194304.0;
  unsigned long   refCount = 10000001.0;
  float quartzFrequency;
  quartzFrequency = (float)refFrequency / (float)refCount;
  quartzFrequency =  quartzFrequency * (float)quartzCount;

  Serial.print("Crystal frequency value: ");
  Serial.println(quartzFrequency, 3);


On Arduino both Float and Double are 32 bit so limit the precision. That cetainly looks like the problem you have,

There is a long long on Arduino that would preserve the precision as such you might be abe to use that but there are obvious disadvantages, it uses much more memory to carry out operations, you would have to convert the float to a long long for precision and probably a long for the decimal point position.

Thank you very much countrypaul. I will try doing it this way!