Solved

asp.net c# 2.0 convert double to percent

Posted on 2006-07-10
5
1,757 Views
Last Modified: 2008-01-09
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
Comment
Question by:fwsteal
5 Comments
 
LVL 9

Expert Comment

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

Cheers!
0
 

Author Comment

by:fwsteal
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

by:
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

by:fwsteal
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

by:kaliyugkaarjun
kaliyugkaarjun earned 250 total points
ID: 17081501
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASP.net VB.net Email  a webpage 3 30
Why is some text in blue in Visual Studio? 6 22
ASP.NET 5 Templates 2 65
Where can I ask about my ASP.NET MVC project? 6 19
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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now