c0000000kie
c0000000kie

Reputation: 129

save a files with a same digits format in julia?

I'm using Julia programming language.

I save each simulation result with a loop, and the parameter value is saved in a file name.

Is there any good way to unify the number of decimal places in file names?

For example,

using DelimitedFiles

for i=0:0.05:1
    a = rand(1)
    writedlm("i=$i.txt", a)
end

then I got

enter image description here

What I want is like below

enter image description here

Thanks for your comment

Upvotes: 3

Views: 135

Answers (1)

Bogumił Kamiński
Bogumił Kamiński

Reputation: 69939

you can use Formatting.jl package. Here is an example (there are many more options; I show you one that I typically use when I want the file names to be nicely sorted):

julia> format.(0.0:0.5:10.0, precision=2, width=5, zeropadding=true)
21-element Vector{String}:
 "00.00"
 "00.50"
 "01.00"
 "01.50"
 "02.00"
 "02.50"
 "03.00"
 "03.50"
 "04.00"
 "04.50"
 "05.00"
 "05.50"
 "06.00"
 "06.50"
 "07.00"
 "07.50"
 "08.00"
 "08.50"
 "09.00"
 "09.50"
 "10.00"

Upvotes: 2

Related Questions