Analogue voltage not displaying deciaml part

Hi team! I have a strange thing happening in some versions of a monitoring system that I've been working with for several years, but not in others running basically identical code. I have analogue voltage readings (between 0.0 and 5.0 volts DC on 2 analogue pins of the arduinoe (A0 and A2). I have defined the voltages asa floats, I carry out the math on the raw data to obtain a deciml value, I specify that this should be displayed to 1 decimal place, and on most of my devices this works fine. Strangely, I have several devices running the same code but with minor changes to other digital inputs that always display the decimal part of the voltage as ".0". It has to be a code issue as all these units that display zero decimal value started with te same base code which I then modify to suit. I've checked the analogue routines in the code for units that work properly and those that don't and they are identical in every way with relation to definitions, math, and display routines. The entire code block is several thousand lines so posting it would be cruel...

I know it's a weird question but has anyone seen this type of issue before? If so, could you give me a clue where I might look to solve this little mystery?


Large amounts of code.
Many of us do not have the time or patience to download large sketches and look through and correct a large amount of code.

Please show us a down sized version of your sketch that still exhibits the same problems you are experiencing.
Since this is your sketch, you should be able to identify irrelevant lines of code and delete those lines.

Also, adding good comments to your code can make things infinitely easier for us to understand what your intentions are in the sketch.
Remember, formatting your sketch using or helps us to help you.

OK..., I'll spend some time and remove the unnecessary areas. I'll check that it still misbehaves and if it does, I'll post it here.



Just post the following few lines of codes:

  1. Acquisition of the analog signal from A0-pin and storing it in a variable (x).
  2. Formatting/processing of the variable of Step-1 and save the result in a variable (y),
  3. Display the magnitude (both integer and fractional part with desired precision) of the variable of Step-2 in Serial Monitor of the Arduino IDE.

It sounds like you have done something like this

float voltage;
int reading = 2000;

void setup()
  voltage = reading / 1023;
  Serial.println(voltage, 1);

void loop()

rather than

  voltage = reading / 1023.0;

The first version uses integer division to occur even though voltage is a float whereas the second version causes the calculation to be done as a float.