www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10001] New: string formatting with underscores

http://d.puremagic.com/issues/show_bug.cgi?id=10001

           Summary: string formatting with underscores
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc


--- Comment #0 from bearophile_hugs eml.cc 2013-04-28 08:16:20 PDT ---
The underscores allowed in number literals are quite handy to improve their
readability (and this avoids some bugs in D code), so maybe it's worth having a
standard simple way to also print numbers with them (one every three digits
before the dot), to improve the output readability:

  format("%_d", 1000000)
writefln("%_d", 1000000)

Expected output:

1_000_000


That notation is not flexible on purpose, so you can't use it to generate a
string like:

1'000'000


Note: currently to!int("1_000") gives an error, so you can't round-trip like
this:

format("%_d", 1000).to!int

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 28 2013