views:

28

answers:

2

in my class i have this property

public decimal Percentage..
    {
        get;
        set;
    }

this value is comming like decimal somethign like this.. -0.0214444 I need to show them somethign like -2.1444

can I change to this formate in my property..

thanks

+1  A: 

You can use the "P" format string to add the percent sign. You can create another property to wrap it or just get Percentage and then call ToString.

public decimal Percentage { get; set; }

public string FormattedPercentage 
{ 
    get { return Percentage.ToString("P"); }
}
Brandon
+2  A: 

Just multiply it by 100.

<%= myObject.Percentage * 100 %>

You can round it to a smaller number of decimal places:

<%= Math.Round(myObject.Percentage * 100, 3) %>

Another way:

<%= string.Format("Percentage is {0:0.0%}", myObject.Percentage) %>
Matt Sherman