2009/05/27

C#- Thousand separator

To add thousand separator to your number, you could do this:

Convert.ToDecimal(yourNumber.Text.ToString()).ToString("N2")
or
Convert.ToDecimal(yourNumber.Text.ToString()).ToString("N4")

where N2 = 2 decimal place and N4 = 4 decimal place.

if you don't want any decimal place you can try this:
Convert.ToInt32(yourNumber.Text.ToString()).ToString("N0")

1 comment:

  1. What if the user types some numbers and clicks the thousand separator button. But he also wants to add decimal places. E.g. using N0 for no decimal places but doing the same thing as a N6 but not showing the decimal places.

    ReplyDelete