Value as % (percentage)

1. ## Value as % (percentage)

Hi Guys,

I ma very new to dotnet and am working on a custom function, see below:

public static string Saving2(object ProdRRP, object ProdWebPrice)
{

if (ProdRRP == null || ProdWebPrice == null)
{
return "";
}
else
{
Double ProdRRPNew = Convert.ToDouble(ProdRRP);
Double ProdWebPriceNew = Convert.ToDouble(ProdWebPrice);
Double Saving = Math.Round (Convert.ToDouble(ProdWebPriceNew -
ProdRRPNew),2);

if (Convert.ToInt32(Saving) ==0)
{
return "";
}
else
{
return "Save " + Saving.ToString("c");
}
}
}

This shows a saving relevant to the RRP price as a £value. Can anyone tell
me how I get it to calculate as a % of the RRP price?

My System Specs

2. ## Re: Value as % (percentage)

saving fraction=(old-new)/old

percentage=fraction*100%

And shouldn't you be declaring the types of the parameters as "Double",
rather than "object"? Note also that the Decimal type is usually more
suitable for money.

Andrew

My System Specs

Value as % (percentage)