-2

I'm converting some VBA code from Excel macro into C# and came across with this line of code.

VBA:

Format(12356, "#,###.00000")

How to translate this to C#?

GSerg
  • 76,472
  • 17
  • 159
  • 346
Veck
  • 125
  • 1
  • 3
  • 13
  • Check [Overview: How to format numbers, dates, enums, and other types in .NET](https://learn.microsoft.com/en-us/dotnet/standard/base-types/formatting-types). You can use `.ToString()`, `String.Format` or string interpolation with a format string. There are built-in standard formats or you can specify your own custom format. The thousand and decimal separators are locale-sensitive but you can specify the locale you want as a `CultureInfo` parameter – Panagiotis Kanavos Apr 04 '23 at 10:15
  • 1
    Are you really using such an old version of C#? – Charlieface Apr 04 '23 at 11:34

1 Answers1

1

You can try, ToString() with same format.

var numStr = 12356.ToString("#,###.00000");
Console.WriteLine(numStr);  //"12,356.00000"

.Net Fiddle

Prasad Telkikar
  • 15,207
  • 5
  • 21
  • 44