Can I change the output data style so that a comma appears when the data is a number? 

Can I change the output data style so that a comma appears when the data is a number? 

Comments

  • JoeAlbahari
    edited January 2023

    You need to add a static ToDump method to your query to intercept the Dump pipeline:

    static object ToDump (object input)
    {
        if (input is int or long)
            return $"{input:N0}";
    
        if (input is float or double or decimal)
            return $"{input:#,##0.###################################}";
    
        return input;
    }
    

    If you define this method in the My Extensions query, it will work for all queries.

  • cannot function, The Source Object is a dynamic List; 
    How to apply the format number to all method dumps?

  • If you define this method in the My Extensions query, it will work for all queries.

  • kunio
    edited January 2023

    Before I'm defined in my query; when I move to my extensions, it's now working. 

    thankyou so much

    Next question

    Can apply format for sum total?

  • Try the latest beta:
    https://www.linqpad.net/linqpad7.aspx#beta

    There are now options in Edit | Preferences to include group separators in numbers without needing to write a ToDump method. It also applies your preferences to total columns and data grids (both formatting and parsing) and handles all local cultures.

  • @JoeAlbahari
    Can apply this feature to LINQPAD V5?

  • A new LINQPad 5 build is planned soon with some backported features, but that one is unlikely to make it. Note that My Extensions is separate for LINQPad 5, so if you implement the static ToDump workaround, it will affect only LINQPad 5.

  • In LINQPAD5 , Can write extension to apply format total columns ?