Well, the formula to compute a percentage is:
Dim v1 As Double = 100
Dim v2 As Double = 200
Dim v3 As Double = 300
Dim v4 As Double = 400
Dim total As Double = v1 + v2 + v3 + v4
Dim p1 As Double = v1 / total
Dim p2 As Double = v2 / total
Dim p3 As Double = v3 / total
Dim p4 As Double = v4 / total
Dim p1Display As String = p1.ToString("P")
Dim p2Display As String = p2.ToString("P")
Dim p3Display As String = p3.ToString("P")
Dim p4Display As String = p4.ToString("P")
Important points here:
- Compute the percent value in its primary, real form. If you have to save it in a repository, keep its real value, not its string representation.
- Display it as a percent only when you are presenting the value to the user. Here I used the
ToString("P")
method to tell that I want the percent-representation of the underlying real value.
- The concept in two points above is valid for all types of data, and especially datetimes. Always handle and store datetime values, not their string representation.
Finally, as it is your question is more a mathematic question than a development one. Kindly, I advise you to improve your skills in mathematics; as a developper, it will make your every-day life way much easier.
Hope this helps. Good work :)
[Edit] To apply the percentage format to a chart label, you can do it this way:
yourChart.ChartAreas.First().AxisY.LabelStyle.Format = "P"