Windows Vista Forums

Value as % (percentage)
  1. #1


    Lez Guest

    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?

    Thanks in advance




      My System SpecsSystem Spec

  2. #2


    Andrew Morton Guest

    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 SpecsSystem Spec

Value as % (percentage) problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Battery maximum charge percentage Rajesh A Vista General 4 26 Jan 2009
Battery percentage isn't changing kirri Vista General 2 17 Nov 2007
Network Usage Percentage Brian H. PowerShell 5 07 Nov 2007
Copying large folders only finds a tiny percentage of files Dale Vista General 0 25 Feb 2007