A couple of problems here. The first is there is no need for an instance name for the performance counter, since you only have one. Secondly, there is a problem with how you are determining the percentage.
See the corrected code with comments:
csharp
System.Management.SelectQuery query = new System.Management.SelectQuery("Win32_MemoryArray");
System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(query);
System.Diagnostics.PerformanceCounter performanceCounter = new System.Diagnostics.PerformanceCounter("Memory", "Available KBytes", true);
//To avoid unnecessary casting, make these all a double
double max = 0;
double final = 0;
double percentUsed = 0;
foreach (System.Management.ManagementObject ManageObject in searcher.Get())
{
max = Int32.Parse(ManageObject["EndingAddress"].ToString());
Decimal gigs = Decimal.Divide(performanceCounter.RawValue, 1000000);
//divide the RawValue by the max to get the percentage used
//then multiply by 100 to convert it to a value between 0 and 100
percentUsed = (performanceCounter.RawValue / max) * 100.0;
final = max - Convert.ToDouble(gigs);
ramProgressBar.Maximum = 100;
}
ramProgressBar.Value = (int)percentUsed;