Mario
Mario

Reputation: 14790

Digit grouping in Eval function

I have this code in ASP.NET 4.5

 <span><%# Eval("Rating").ToString()+" " %></span>

to display the rating, but want to group the digits based on the user locale, how can I achieve this directly in aspx without code behind ? 1,000 instead of 1000

Upvotes: 0

Views: 376

Answers (3)

errorintheapplication
errorintheapplication

Reputation: 155

You can try this.

  <%#Eval("Rating","{0:0,00}").ToString() %>

Upvotes: 0

p.s.w.g
p.s.w.g

Reputation: 149040

You could use this:

<span><%# ((int)Eval("Rating")).ToString("n0")+" " %></span>

Or this:

<span><%# ((int)Eval("Rating")).ToString("#,###")+" " %></span>

Further Reading

Upvotes: 1

weston
weston

Reputation: 54801

Try:

Eval("Rating").ToString(CultureInfo.CurrentUICulture)

Assuming int is the return type of Eval

Upvotes: 1

Related Questions