Question

I would like to format this kind of number:

1234567.99 (obviously all thousands digits are optional)

In this way: 1.234.567,99

I know it is possible with Eval, but I didn't find an useful guide to do this.

Could you help me?

Thanks

Was it helpful?

Solution

There is an overload of Eval that takes three parameters (the link also contains a sample):

  • Container
  • Expression
  • Format

For the format, you'd specify "{0:c}" or whatever format you like. For a list of the Standard Numeric Format Strings, see this link. If you want to specify your format with a custom format string, e.g. use "{0:#,##0.00}".

OTHER TIPS

You can use the ToString() extension

var value = 1234567.99;
Console.WriteLine(value.ToString("C3", CultureInfo.CurrentCulture));

Or by stating your culture

Console.WriteLine(value.ToString("C3", CultureInfo.CreateSpecificCulture("sv-SE")));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top