In Julia, when I want to print a number "4" with the width of 10, I do:
@printf("%10d", 4)
If I want to set the width as the length of a specific string, for example:
mystr = "Hello World"
how to change 10 in "%10d" to length(mystr)?
Checkout the Formatting library:
using Formatting
printfmt("{:$(length("Hello World"))d}", 4)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With