W
W
WWH2018-06-21 11:26:01
C++ / C#
WWH, 2018-06-21 11:26:01

How does this printf() work?

How does printf() actually work? Why
float f = 6635.543
printf("%10.2f", f);
and
printf("%2.2f", f");
Give the same answer?
What does the first number after % mean?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
netrox, 2018-06-21
@netrox

This is for formatting.
https://metanit.com/cpp/c/2.14.php

R
res2001, 2018-06-21
@res2001

By default, missing characters are replaced with spaces, but zeros can also be specified: %06.2f
Width specifies the minimum field size, i.e. this is not a fixed size and can be larger if needed.
www.cplusplus.com/reference/cstdio/printf/?kw=printf

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question