s.milziadi
s.milziadi

Reputation: 705

Number format with Eval in ASP.NET

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

Upvotes: 1

Views: 9228

Answers (2)

Markus
Markus

Reputation: 22481

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}".

Upvotes: 3

Eric Herlitz
Eric Herlitz

Reputation: 26307

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")));

Upvotes: 0

Related Questions