-1

Is there a better way to write this function that will add a comma to a number?

private static string FormatNumber(decimal? number)
{
    if (!number.HasValue)
    {
        return string.Empty;
    }
    // use the different formatter for long numbers
    return number > 99999 ? $"{number.Value:#,###.##}" : $"{number.Value:G29}";
 }
AustinWBryan
  • 3,249
  • 3
  • 24
  • 42
Jefferson
  • 173
  • 2
  • 12
  • 32

1 Answers1

0

The following works:

private static string FormatNumber(decimal? number)
{
    if (!number.HasValue)
    {
        return string.Empty;
    }
    return $"{number.Value:#,###.##}";
 }
Peter Smith
  • 5,528
  • 8
  • 51
  • 77