Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

asp.net c# 2.0 convert double to percent

Posted on 2006-07-10
5
Medium Priority
?
1,791 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

636 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