# Simple formatting problem

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.

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:

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

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!

1 Like