Ok, I thought I was clear on the double, int, float, decimal etc types. I used typed variables in VB and was comfortable with them. I've just started C# and out of the gate I feel totally clueless. I keep assigning double type variables expressions with division and when I out put the value the decimal portion is chopped off and I get a whole number. Here's my question for the following I get:
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
double x = 4/12;
double y = 7/12;
double z = x/y;
Console.Write("z=" + z);
Console.Write("\n");
Console.Write("x=" + x);
Console.Write("\n");
Console.Write("y="+ y);
Console.Read();
}
}
}
z=NAN
x=0
y=0
Or if the number is larger and I use division the answer truncates the decimal and I get a whole number EX:
double example = 12 + (2/12)
this gives me 12 as a result, could someone please explain, I'm sorry for such a simple question, but I'm at a loss. I thought doubles were meant to hold numbers with a floating decimal point.
Thanks for any help : )