Solved

# asp.net c# 2.0 convert double to percent

Posted on 2006-07-10
1,746 Views
How do I convert a double value to percent for comparison?

Example of code with static entries commented:
Double C = Double.Parse(TextBox1.Text); //77500
Double R = Double.Parse(TextBox2.Text); //33600
Double I = Double.Parse(TextBox3.Text); //241500
Double TCA = C + R + I;

Double AP = Double.Parse(TextBox4.Text); //129000
Double NP = Double.Parse(TextBox6.Text); //8400
Double OCL = Double.Parse(TextBox7.Text); //117000
Double TCL = AP + NP + OCL;

Double CR;
CR = TCA / TCL;
Label9.Text = CR.ToString();
if (CR < 2.0)
Label18.Text = "CR is under";
else
Label18.Text = "CR is above";

End Results:

Name      value                  compareto
CR            1.98484848484848          2.0%
0
Question by:fwsteal

LVL 9

Expert Comment

ID: 17076121
Hi fwsteal,
You want to compare it to percent of what?

Cheers!
0

Author Comment

ID: 17077498
format the display of the CR to display as a % such as:
1.98%
and still be able to compare it:
if (1.98 < 2.0)

so my report description can read as: 1.98% is less than 2.0%, so don't buy.
0

LVL 9

Accepted Solution

bele04 earned 250 total points
ID: 17078478
Since you're just going to display it why don't you just append it to the the string like:

Response.Output.Write("{0:#.##}% is less than 2.0%, so don't buy", CR);

or if you're going to display it to a label:

label1.Text = CR.ToString("{#.##}") + "% is less than 2.0%, so don't buy.";
0

Author Comment

ID: 17080995
CR.ToString("#.##") = .62

I'm not sure how to display it as 62.0?

How should the following be written? CR.ToString("#.##") + "%";
0

LVL 8

Assisted Solution

kaliyugkaarjun earned 250 total points
ID: 17081501
0

## Featured Post

### Suggested Solutions

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…