# @printf not consistent with C printf?

**URL:** https://discourse.julialang.org/t/printf-not-consistent-with-c-printf/64136
**Category:** General Usage
**Tags:** question, formatting
**Created:** [July 6, 2021, 8:56am UTC](https://discourse.julialang.org/t/printf-not-consistent-with-c-printf/64136 "2021-07-06T08:56:10Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![floswald](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/floswald/32/195_2.png) [@floswald](https://discourse.julialang.org/u/floswald)
#### Post date: [July 6, 2021, 8:56am UTC](https://discourse.julialang.org/t/printf-not-consistent-with-c-printf/64136/1 "2021-07-06T08:56:11Z")

</div>

quick question about `%02.3f` format specifier - that should left pad zeros to the left of the comma sign, and have 3 digits afterwards, like here [formatting - 'printf' with leading zeros in C - Stack Overflow](https://stackoverflow.com/a/5007518)

```julia
julia> @printf("%02.3f" ,π)
3.142 # I wanted 03.142

```

---

<div class="post-metadata">

### Author: ![ess3sq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ess3sq/32/26834_2.png) [@ess3sq](https://discourse.julialang.org/u/ess3sq)
#### Post date: [July 6, 2021, 9:13am UTC](https://discourse.julialang.org/t/printf-not-consistent-with-c-printf/64136/2 "2021-07-06T09:13:12Z")

</div>

Try `@printf "%06.3f" π` (the field size specifiers seems to indicate the min length of the entire stringified float, not the integer part…), which I find unexpected too.

---

<div class="post-metadata">

### Author: ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)
#### Post date: [July 6, 2021, 9:26am UTC](https://discourse.julialang.org/t/printf-not-consistent-with-c-printf/64136/3 "2021-07-06T09:26:41Z")

</div>

That’s the correct behavior. As @ess3sq says the field width (the number you give before the `.`) specifies the width of the entire field. This is generally what you want for creating nicely aligned ASCII tables:

```julia
julia> v = rand(5);

julia> for x in v
         @printf "%08.3f\n" 10^3x
       end
0019.654
0009.578
0007.408
0026.634
0507.169

```

or with spaces instead of `0`:

```julia
julia> for x in v
         @printf "%8.3f\n" 10^3x
       end
  19.654
   9.578
   7.408
  26.634
 507.169

```

---

<div class="post-metadata">

### Author: ![floswald](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/floswald/32/195_2.png) [@floswald](https://discourse.julialang.org/u/floswald)
#### Post date: [July 6, 2021, 9:32am UTC](https://discourse.julialang.org/t/printf-not-consistent-with-c-printf/64136/4 "2021-07-06T09:32:57Z")

</div>

a yes i see - my bad! thanks
