Skip to content

g format loses to much information, #95

Open

Description

@ryofurue

[I misspelt "too" in the title. Sorry! I don't know how to fix it.]

I'm quite surprised by this:

using Format
format("{1:.2g}", 0.00093) # -> "0.00"

whereas this Fortran program

program main
  write(*,"(G0.2)") 0.00093d0 ! -> "0.93E-3"
end program main

prints "0.93E-3".

I thought the whole point of the G format specifier is to minimize information loss while minimizing the horizontal space. Is Format.jl's behavior intended? or am I missing something?

Format v1.3.7 on Julia 1.12.4.

Activity

  1. ScottPJones commented on Oct 5, 2026

    @ScottPJones
    Member

    I'll start looking at this now (I'd been ill for a while, didn't see this).
    You can use the StrFormat.jl instead for now, i.e. f"\%.2g(0.00093)" which does give correct results.
    (I inherited the python style formatting code from the now obsolete Formatting.jl, and it has two totally different code paths for the C style and the Python style formatting functions, unfortunately. Since I don't use the python style ones, I hadn't caught all of the errors in that code while trying to clean it up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions