Show as percent (%)
1. ## Show as percent (%)

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

}

My System Specs

2. ## Re: Show as percent (%)

"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 "%".

My System Specs

3. ## Re: Show as percent (%)

Hi Guys,

To advise, I have sorted it now thanks

"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
>
> }

My System Specs

4. ## Re: Show as percent (%)

object.ToString("P") where object is a numeric type will return percentages.

100.ToString("P") => "100 %"

Mike.

"PvdG42" <pvdg42@newsgroup> wrote in message
news:O57Mp9\$fKHA.1648@newsgroup

>
> "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 "%".

My System Specs

Show as percent (%) problems?

 Similar Threads Thread Thread Starter Forum Replies Last Post PoShNoob PowerShell 1 15 Mar 2010 dmex Vista News 3 25 Sep 2008 rwh Vista music pictures video 8 01 Mar 2008 Tom Moreau PowerShell 1 01 Feb 2008 Daniel- Sydney Vista General 1 14 Oct 2007