Trouble When Printing Decimals

I am trying to print the decimal value of a variable. I have it set to print to a display that I have connected as well as the Serial Monitor. I have tried a combination of formatting options from the Print() section of the arduino website, none of which have aided me.

For example:

I have a stored value that I want to increment by .1 every 1s. It works when I change the increment to 1, but when it is .1, it returns zero each time. Additionally, it does not rollover the value from 0 to 1 when the tenth increments should have accumulated a whole number.

I'm using a Metro M0.

I have attached my project file.

Thanks!

Metro_Matrix_PrintChange_Testy.ino (572 Bytes)

int counter = 0;

counter must be declared as float.

int increment = 0.1;

Your increment variable is an int data type. The int data type holds integers or whole numbers only. The result of the assignment is increment = 0. To work with decimal fractions, float is the proper data type.

Arduino data types.

florinc:

int counter = 0;

counter must be declared as float.

and increment too

float counter = 0;
float increment = 0.1;
matrix.println(counter, 2); // 2 decimal places

Wow, what an oversight. Thanks for the help everyone, changing the data type solved everything.