# How to display multiple numbers with varying decimal lengths in array, C programming?

I'm trying to associate numbers between two arrays, and one of the arrays contains 500 numbers. Some of the numbers contain 2 decimal places, while others contain 3. How do i read off the numbers as is.

I tried printf("%.3f",floatvar); but it only displayed correctly when the number DID have 3 decimal places. It however made up an added number for those that had only 2 decimal places.

How do I display a float as is, or make it so that if it only contains 2 decimal places it will just add a zero after like 4.23 would be read 4.230.

I cant round because I have to calculate exact mean of percentages.

## Answers

Did you try printf("%g",floatvar);?. Anyway, printf("%.3f",floatvar) should add a trailing 0 for numbers with 2 decimals though.