Convert variable (integer) to percentage in asp.net mvc

ika palad 86 Reputation points
2021-11-06T00:40:13.667+00:00

Hello Community,

I'm trying to convert the variable integer data into percentage in creating a bar chart. However it seems it is not working. What I missed

string x1 = var_Product_name;                         
                  int y1 = Tools.ConvertToInt_02(var_Amount);     
                  int y2 = Tools.ConvertToInt_02(var_Amount)/ 100.ToString("0.00%");        //This is the code I used to convert the var_Amount to get the percentage and display as data series in bar graph together with the var_Amount value however this isn't working

BarChartData_Product_Records_Data_View.Add(new BarChartSourceData_Product_Records_Data_View(x1, y1, y2));
Developer technologies | ASP.NET | Other
{count} votes

1 answer

Sort by: Most helpful
  1. Yijing Sun-MSFT 7,096 Reputation points
    2021-11-08T07:16:21.347+00:00

    Hi @ika palad ,
    You could use double or decimal.

    int y2= Convert.ToInt32(Math.Round(((double)var_Amount) * 100, 0));  
    

    Best regards,
    Yijing Sun


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.