• Rob (unregistered)

    TRWTF is not allowing "#0.## \u2030" like in Java.

  • A.N.O Nymos (unregistered)

    This looks like they're trying to set-up an interpolated string (i.e.: $"{0:#,##0.00;(#,##0.00)}", which would just result in "0.00;(0.00)"). But as far as I know, you can't use interpolated strings like this:

    string str = $"{myfield.DataFormatString}"; //Won't work, or at least won't print "0.00;(0.00)"
    

    But maybe this isn't C#, and it works just fine in whatever language they're using.

  • (nodebb)

    If you're typing it frequently, you can use Option+Shift+R to type ‰ on macOS. But let's be honest, 99.999% of people (or 999.99‰ of people?) aren't typing it frequently and are going to have to google it, like I did just now.

  • (nodebb) in reply to A.N.O Nymos

    It's probably C# and I doubt they're trying to use the $ syntax. IMO more likely it's like this:

    myField.DataFormatString = "{0:#,##0. ... }";  // assume this a valid format string.
    ...
    // much later elsewhere in the code
    myTextBox.Text = String.Format (Myfield.DataFormatString, myField.Value);
    

    And you're correct about the $ syntax. MSFT says only works with a literal string. It's a compile-time transformation into formatting calls. See the first sentence here: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated

  • A.N.O Nymos (unregistered) in reply to WTFGuy

    Agreed, your answer is most likely correct. I forgot that string.Format also allows formatting after its placeholders. If I use string.Format at all, I usually just use the basic placeholders (e.g.: "{0} - {1}") and rarely need any specific formats, and when I do I usually put the formatting with the arguments. E.g.: string.Format("Today: {0}", DateTime.Now.ToString("yyyy-MM-dd"));

  • (nodebb)

    The designers of C printf realized long ago that you sometimes need to parameterize some of the formatting options, so you can use * in place of things like the field width to get the value from the arguments. This doesn't handle all the cases where you need to build format strings dynamically, but it gets the most common ones.

  • Klimax (unregistered)

    Funnily enough, in C++ 20 vformat can be used with formatting passed in as variable.

  • (nodebb)

    To be fair, that format specifier is just useful for Dungeon & Dragons campaigns anyway. Every civilized country on this planet is using metric for ages now :-).

  • (nodebb) in reply to WTFGuy

    Yeah, there's actually a lot more to string interpolation in C#. It also uses best-performance string operations and even StringBuilder when appropriate. They could go full in with optimizations since there was no backwards compatibility holding them back.

    The nice thing is you can even build format strings and then cache them to use them for string operations that expect format strings. Super useful for code generators and to basically use the $ operator to do stuff like escape SQL properly with minimum overhead directly in the command like shown here: https://learn.microsoft.com/en-us/ef/core/querying/sql-queries?tabs=sqlserver.

  • (nodebb)

    wait, there's a format string around since .Net 1.1 that I don't know about ?

  • (nodebb) in reply to DJSpudplucker

    string.Format is around since the beta, so pre-net 1.0, the current extended version with additional support for stuff like CultureInfo.InvariantFormat is around since 1.1 (because that itself was introduced with 1.1). Only interpolation is new since .net core cause a lot of developers are just too sloppy to use the correct composition methods in the right context.

    Addendum 2026-10-23 05:47: Plus I have to add there was a major change how .net handles strings internally between v1.x and v2.0 which had major implications regarding StringBuilder usage, so it's not only sloppiness but also incompetence caused by poorly communicated changes by MS that made interpolation well. You just have to ask a dev when strings will be interned and you'd be surprised how much nonsense and outdated information you will be faced with.

  • (nodebb) in reply to Rob

    It is allowed. Not sure why the example uses concatenation instead...

  • (nodebb) in reply to adamantoise

    option shift r gives me this: Â, on my Mac with a British English keyboard. After a bit of research involving keyboard viewer, I have discovered it is option shift e. If you have a different keyboard YKMMV

  • Strahd Ivarius (unregistered)

    Based on some rumors from Claude, the next iteration of dotNet will require spending a bitcoin to use any US date format...

  • (nodebb)

    WinCompose, so I can type ‰ by CAPSLOCK (my compose key) % o.

Leave a comment on “Readable Formats”

Log In or post as a guest

Replying to comment #705602:

« Return to Article