Formatting syntax question

I have this code snippet:

using Formatting
printfmtln("{} total RAM", format(Sys.total_memory(), precision=2, autoscale=:binary))

which nicely prints what I expected:

15.56Gi total RAM

Is there a way to pack both formatting parameters precision=2, autoscale=:binary into the first item’s placeholder {}?

Do you mean something like:

println("$(format(Sys.total_memory(), precision=2, autoscale=:binary)) total RAM")
1 Like

I don’t think so. If you check the source code, the format spec mimics the Python format library. Specifically, autoscale isn’t supported. Precision is OK though.

It’s an interesting variation, but I meant something like this:

printfmtln("{:.2f, autoscale=:binary} total RAM", Sys.total_memory())

I know, I know - make a pull request. :wink:

1 Like