Вопрос

am using Ms chart and i just need a number or numeric value for percentage calculation so for that am using #PERCENT{N} but its returning a decimal value like 0.45 0.78 0.11 etc.. which i do not need, i want it should give me like only numeric value like 45 78 11 23 etc.. please see my below code. its just a part of my coding am posting here. please help me out.

LegendCellColumn PercentageColumn = new LegendCellColumn();
PercentageColumn.Text = "#PERCENT{N}";
PercentageColumn.HeaderText = "%";
PercentageColumn.Name = "Percentage %";
//avgColumn.HeaderBackColor = Color.WhiteSmoke;
Chart1.Legends[0].CellColumns.Add(PercentageColumn);

What should i make with this to get only numeric value with out decimal value.

Thanks

Это было полезно?

Решение

Decimal outDec;
if (Decimal.TryParse("<some string>", out outDec))
{
    // Sets Decimal as a Percentage out of 100
    PercentageColumn.Text = Convert.ToInt32(outDec * 100).ToString();
}

Edit

To do it specifically using String formatting :

PercentageColumn.Text = "#PERCENT{P0}";

From: Social.MSDN - Shows Percentages on Pie Chart ( Aspnet) and MSDN - Standard Numeric Format Strings

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top