Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

sprintf1 can format C-style format specification string like "p=%.1f" in Julia 1.6+ but cannot do it on Julia 1.4 #105

Open
singularitti opened this issue Apr 18, 2022 · 0 comments

Comments

@singularitti
Copy link

singularitti commented Apr 18, 2022

As the title suggests, I want to print a string like "p=20.0" using sprintf1 with a C-style format specification string. For example,

julia> using Formatting, Printf

julia> sprintf1("p=%.1f", 20)
ERROR: Only one AND undecorated format string is allowed
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] checkfmt at /Users/qz/.julia/packages/Formatting/BwWBf/src/cformat.jl:12 [inlined]
 [3] generate_formatter(::String) at /Users/qz/.julia/packages/Formatting/BwWBf/src/cformat.jl:23
 [4] sprintf1(::String, ::Int64) at /Users/qz/.julia/packages/Formatting/BwWBf/src/cformat.jl:3
 [5] top-level scope at REPL[12]:1

julia> @sprintf("p=%.1f", 20)
"p=20.0"

julia> versioninfo()
Julia Version 1.4.2
Commit 44fa15b150* (2020-05-23 18:35 UTC)

But it does work on Julia 1.6+:

julia> sprintf1("p=%.1f", 20)
"p=20.0"

julia> versioninfo()
Julia Version 1.7.2
Commit bf53498635 (2022-02-06 15:21 UTC)

As you can see, @sprintf actually has a wider range of "%Fmt" that it can take. Can I still do that with a C-style format specification string in Formatting.jl?

@singularitti singularitti changed the title Can sprintf1 format something like "p=%.1f"? sprintf1 can format C-style format specification string like "p=%.1f" in Julia 1.6+ but cannot do it on Julia 1.4 Apr 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant