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.


Need Your Help

Naming HTML input arrays as [] or [0]?

php html arrays

I need to create multiple forms with a single submit (save) button.

Why can I connect to http://127.0.0.1:8000/ but not to http://192.168.1.6/

django macos sockets networking firewall

I'm running OS X Mountain Lion on a machine with local IP address 192.168.1.6 (as reported by both the Network utility and ifconfig) and am running a local (Django) development web server on port 8...