Solved

asp.net c# 2.0 convert double to percent

Posted on 2006-07-10
5
1,782 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 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

691 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