Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Does a floating point format's width option exclude the decimal point when it's the last element?

I’m reading this document about the secret of printf in order to write my own printf and I found the 2nd ("%5.0f.", e) with e = 2.718281828 printf floating point format and what it produces confusing, why is there four spaces before the 3 and the decimal point?

I thought the output would be 3. with three spaces before the number 3 as the decimal point takes one space itself.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

In the format string "%5.0f." there are two parts: a floating point specifier %5.0f and a literal .. The two are not attached in any way.

The first part prints 4 spaces followed by the number 2, and the second part just prints . independently of the first part.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading