"EddWood" <Edd_nospam_@newsgroup\hotmail.co.uk> wrote in message
news:9625DD8A-A61A-4DCE-8211-F4EF1FA192FD@newsgroup
> Hi Guys,
>
> I am new to dotnet and have this custom function to show a £value saving
> based on the ProdPrice and ProdWPrice which works fine, but I am looking
> for the value to be shown as a percentage % rather that a £value for
> another function.
>
>
> public static string saving(object ProdPrice, object ProdWPrice)
> {
>
> if (ProdPrice == null || ProdWPrice == null)
> {
> return "";
> }
> else
> {
> Double ProdPriceNew = Convert.ToDouble(ProdPrice);
> Double ProdWPriceNew = Convert.ToDouble(ProdWPrice);
> Double Saving = Math.Round (Convert.ToDouble(ProdWPriceNew -
> ProdPriceNew),2);
>
> if (Convert.ToInt32(Saving) <=0)
> {
> return "";
> }
> else
> {
> return "Save " + Saving.ToString("c");
> }
> }
>
> Thanks
>
> } You want Saving as a percentage of what? Regardless, it's a matter of doing
the math. Do whatever division is needed to get the decimalfraction (e.g.
0.1325). Multiply the result by 100 (0.1325 becomes 13.25). Then add a "%"
to the output string.
You can also use the "P" format specifier with ToString() to automate the
multiplication and addition of the "%".