f = open("test.txt", "w")
println(f, 1/3)
close(f)
julia> f = open("test2.txt","w")
IOStream(<file test2.txt>)
julia> @printf(f,"%0.2f",1/3)
julia> close(f)
julia> using Formatting
julia> fmt2 = generate_formatter("%1.2f")sprintf_JTEuMmY! (generic function with 1 method)
julia> fmt3 = generate_formatter("%1.3f")sprintf_JTEuM2Y! (generic function with 1 method)
julia> @time fmt2(31231.345435245) 55.763 milliseconds (33974 allocations: 1444 KB)"31231.35"
julia> @time fmt2(31231.345435245) 13.573 microseconds (15 allocations: 608 bytes)"31231.35"
julia> @time fmt3(31231.345435245) 11.193 milliseconds (5882 allocations: 254 KB)"31231.345"
julia> @time fmt3(31231.345435245) 16.231 microseconds (15 allocations: 608 bytes)"31231.345"
Hi, I hope you don’t mind a direct e-mail.
I was pointed at your Formatting.jl package, after I’d made the suggestion of adding a fmt function in a new package,
and kmsquire pointed out that there was already a Formatting.jl package, which is where it should go, and then
when I investigated, I saw that it had a fmt function that was almost exactly what I was suggesting.
I was wondering what you’d think of me adding my idea (renamed possibly `sfmt` to avoid the naming conflict`) to your very
nice package (which I think should be in Base, instead of so much *unused* stuff like “RopeString” ;-) ).
My idea was the following:
sfmt( value [, format [, format arguments] ] )
The reason to have the value first, is that you could have methods added to have a default format for specific types.
For example, the C sprintf(buf, “%*s”, 8, string) would become something like:
sfmt( string, “*s”, 8)
What do you think?
Thanks, Scott