So it is easy enough to optionally format to two decimal places if non-zero i.e:
String.Format("{0:0.##}", 123.451); // 123.45
String.Format("{0:0.##}", 123.4567);
(Taken from https://stackoverflow.com/a/21751068/2482265)
And it's easy enough to format with commas:
String.Format("{0:n}", 1234);
And with commas and no decimals:
String.Format("{0:n0}", 1234);
(Taken from https://stackoverflow.com/a/105793/2482265)
But how about with commas and 2 decimals if decimals are non zero, but otherwise no decimals
So
10000000 -> 10,000,000
10000000.234 -> 10,000,000.23
10000000.05 -> 10,000,000.05
Note that if the solution gives 10000000.1 -> 10,000,000.1
That would be acceptable as although I want 2 decimal places, I am infact not dealing with money, so the 2nd decimal place being zero should mean it is not displayed.