Home

Footer Sum ignores output formatting

Hello,

first thanks for the great tool.

void Main()
{
var result = new List();
result.Add(new Test(){Product = 1000000});
result.Add(new Test(){Product = 200000.5});
result.Dump();
}

public class Test{
public double Product;
}

public static object ToDump(object input)
{
if (input is int || input is long) return $"{input:N0}";
if (input is double o) return $"{o:N1}";
if (input is decimal d) return $"{d:n2}";
return input;
}

results in

to the ToDump is ignored for the footer (linqpad 7 and 8). Is there a way to fix/force that?

thanks in advance
Martin

Comments

  • I realise that this is a simple example just to illustrate your point, but most of the issues I have had with this have been resolved in Version 8.4 with the introduction of DumpOptions. See https://www.linqpad.net/LINQPad8.aspx for more details.

    There is also an easier way in Edit/Preferences/Formatting providing you want this to apply a style for every script.

    But assuming you wish to vary the formatting per script, DumpOptions may be the way to go.

    As an example, this allows me to do things like

    void Main()
    {
    
        var result = new List<Test>();
        result.Add(new Test() { Product = 1000000 });
        result.Add(new Test() { Product = 200000.5 });
        result.Dump(new DumpOptions { FormatStrings = new DumpFormatStrings { RealNumber = "#,##0.0" } });
        result.Dump(new DumpOptions { FormatStrings = new DumpFormatStrings { RealNumber = "#,##0.00" } });
        result.Dump(new DumpOptions { FormatStrings = new DumpFormatStrings { RealNumber = "e5" } });
        result.Dump(new DumpOptions { FormatStrings = new DumpFormatStrings { RealNumber = "p" } });
    }
    
    public class Test
    {
        public double Product;
    }
    

    Which produces something like

    You can also set the defaults per script with DumpOptions.Default.

    There may not be a way to dump a grid with multiple columns which have multiple different styles for different columns (at least not without losing the totals at the bottom of the grid on some of the columns), but that has not really been a big issue for me so I haven't played around with it.

  • works like a charm. Thanks for the input

Sign In or Register to comment.