z1n*_*Y5A 3 string-formatting elixir
我可以在 Erlang 中做到这一点:
io:fwrite("~.16X~n", [-31,"0x"]).
-0x1F
ok
Run Code Online (Sandbox Code Playgroud)
但不是在 Elixir 中:
:io.fwrite("~.16X~n", [-31,"0x"])
** (ArgumentError) argument error
(stdlib) :io.format(#PID<0.54.0>, "~.16X~n", [-31, "0x"])
为什么不?
为什么不使用Integer.to_string/2?
iex(1)> Integer.to_string(-31, 16)
"-1F"
Run Code Online (Sandbox Code Playgroud)