# Simple formatting problem

**URL:** <https://discourse.julialang.org/t/simple-formatting-problem/76667>\
**Category:** General Usage\
**Tags:** io\
**Created:** [February 18, 2022, 1:51am UTC](https://discourse.julialang.org/t/simple-formatting-problem/76667 "2022-02-18T01:51:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bob\_Bass](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bob_bass/32/33379_2.png) [@Bob\_Bass](https://discourse.julialang.org/u/Bob_Bass)\
**Post date:** [February 18, 2022, 1:51am UTC](https://discourse.julialang.org/t/simple-formatting-problem/76667/1 "2022-02-18T01:51:37Z")

</div>

Hi.  
I’m working through “Julia Bit-By-Bit” and following is an exercise from chapter 2:

You are required to print the values of the integer variables b , h and n . Write a  
statement which prints b with its rightmost digit in column 10, h with its rightmost  
digit in column 20 and n with its rightmost digit in column 30.

I’ve tried many different ways, e.g.:

‘’’  
function f()  
b = 1  
h = 2  
n = 3  
@printf(“%-10d\n%-20d\n%-30d\n”, b, h, n)  
end  
‘’’

but I always end up with something like:

1  
2  
3

when what I think I want (if I’m reading the question correctly) is more like:

```
                     1 |
        2 |

```

3 |

where | signifies the right margin (not printed).

Is this possible using @printf, which is what was covered in this chapter)? Or am I misunderstanding the question?

Thanks for taking the time to help.

P.S Lol, I can’t even get the formatting to work right on the number 3 above, but I hope you get my meaning.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [February 18, 2022, 1:56am UTC](https://discourse.julialang.org/t/simple-formatting-problem/76667/2 "2022-02-18T01:56:30Z")

</div>

Does not `-` mean left-justify? BTW: use a sequence of three back tics (`) to get quoted code.  
You know, the thing that produces “accent grave” in french text…

Look at the output of this function:

```julia
function f()
b = 1
h = 2
n = 3
@printf("%-10dSTOP\n%-20dSTOP\n%-30dSTOP\n", b, h, n)
end

```

---

<div class="post-metadata">

**Author:** ![Bob\_Bass](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bob_bass/32/33379_2.png) [@Bob\_Bass](https://discourse.julialang.org/u/Bob_Bass)\
**Post date:** [February 18, 2022, 2:34am UTC](https://discourse.julialang.org/t/simple-formatting-problem/76667/3 "2022-02-18T02:34:54Z")

</div>

Thank you, Petr!  
I thought I tried a positive width value, but scrolling back I see that I didn’t.  
Your solution works correctly (using right-justification rather than left-justification)  
Thanks for all the corrections; I will use graves to quote code going forward.  
You’re awesome!
