Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

printing numbers with the width of the length of a specific string in Julia

Tags:

printf

julia

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)?

like image 483
Chang Avatar asked Dec 07 '25 02:12

Chang


1 Answers

Checkout the Formatting library:

using Formatting
printfmt("{:$(length("Hello World"))d}", 4)
like image 65
Chisholm Avatar answered Dec 09 '25 19:12

Chisholm