Value as % (percentage)

  • Thread starter Thread starter Lez
  • Start date Start date
L

Lez

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?

Thanks in advance
 
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
 
Back
Top