?
Solved

asp.net c# 2.0 convert double to percent

Posted on 2006-07-10
5
Medium Priority
?
1,785 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 1000 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 1000 total points
ID: 17081501
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

762 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