473,405 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How to represent double in string

I declared 2 integers 'numerator' and 'denominator' and a double 'result'.
If Numerator = 5 and deniminator = 145 then why when I put result in a
string do I get 0?
Example for a label text property:
myLabel.Text= numerator + " / " + denominator + " = " + result;
I get this: 5 / 145 = 0

Where's the decimal? This is a no brainer but I guess I'm lacking in that
department.

Thanx,
Poe
Nov 16 '05 #1
2 2300
Hi Poewood,

Since both numerator and denominator are type int the expression 5/14
results in type int. The value is less than 1 and gets truncated, leaving
0. If you want the expression to evaluate to a double, do this:

double result = (double)numerator / (double)denominator;

Joe
--
Joe Mayo, Author/Instructor
Need C#/.NET training?
visit www.mayosoftware.com
C# Tutorial - www.csharp-station.com

"Poewood" <Po*****@discussions.microsoft.com> wrote in message
news:BB**********************************@microsof t.com...
I declared 2 integers 'numerator' and 'denominator' and a double 'result'.
If Numerator = 5 and deniminator = 145 then why when I put result in a
string do I get 0?
Example for a label text property:
myLabel.Text= numerator + " / " + denominator + " = " + result;
I get this: 5 / 145 = 0

Where's the decimal? This is a no brainer but I guess I'm lacking in that
department.

Thanx,
Poe

Nov 16 '05 #2
> myLabel.Text= numerator + " / " + denominator + " = " + result;
Try:
myLabel.Text = Convert.ToString(numerator) + " / " +
Convert.ToString(denominator) + " = " + Convert.ToString(result);

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: bartek | last post by:
Hello, I've been pondering with this for quite some time now, and finally decided to ask here for suggestions. I'm kind of confused, actually... Maybe I'm thinking too much... Brain dump...
24
by: deko | last post by:
I'm trying to log error messages and sometimes (no telling when or where) the message contains a string with double quotes. Is there a way get the query to insert the string with the double...
4
by: (PeteCresswell) | last post by:
Is his just a flat-out "No-No" or is there some workaround when it comes time for SQL searches and DAO.FindFirsts against fields containing same? I can see maybe wrapping the value searched for...
22
by: Fred Ma | last post by:
I'm using the expression "int a = ceil( SomeDouble )". The man page says that ceil returns the smallest integer that is not less than SomeDouble, represented as a double. However, my...
2
by: guoqi zheng | last post by:
We can enum to represent a interger using a string. But how can we use enum to represent string below is what I want to achieve. Public Enum country Netherlands = "nl" America = "US" France...
5
by: Matthew Zhou | last post by:
I check the ISO 9899 standard, \r (carriage return) Movesthe active position to the initial position of the current line. What does it do? How to input? I tried to use Flex to check this...
5
by: wshaer | last post by:
Hi This is the task: and these are my classes: public class Engine{ // Declare the varibles
6
by: mrdoommaster | last post by:
Hi, How do I represent a constructor in UML? Say I have a class named Foo. Would it look like so: +Foo( some_val : int ) Is the above correct? Thanks for reading.
2
by: James Harris | last post by:
I'm trying to make sense of the standard C data sizes for floating point numbers. I guess the standards were written to accommodate some particular floating point engines that were popular at one...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.