printf question

Is it possible to have printf format my output from

1
2
3
4
5
6
7
8
9
10
5250.000000000000 
5512.500000000000 
5788.125000000001 
6077.531250000001 
6381.407812500002 
6700.478203125002 
7035.502113281253 
7387.277218945315 
7756.641079892581 
8144.47313388721


to this

1
2
3
4
5
6
7
8
9
10
5250.0
5512.5
5788.125
6077.53125
6381.4078125
6700.478203125
7035.50211328125
7387.277218945313
7756.641079892578
8144.473133887207



or do I have to process my data outside of printf?
Last edited on
printf("%5.1f", var);

This tells the compiler to reserve 5 spaces for a floating point value with 1 number past the decimal. So if you have a 10 digit number change the 5 to 10, and change the 1 to however many decimal places you want. Keep in mind the first number includes the decimal spaces, so a 10 would be for a number that is up to 10 digits including the numbers after the decimal, after that it just overflows the 10 spaces.
Last edited on
Topic archived. No new replies allowed.