if i divide 10 / 4 ill get a 2 when i should get a 2,5..in vb if we did 10 \ 4 we'd get a 2,5 and if we did 10 / 4 we'd get a 2...but how do i do the \ in C#? i noticed the MOD operator doesnt exist in C# too =\
Printable View
if i divide 10 / 4 ill get a 2 when i should get a 2,5..in vb if we did 10 \ 4 we'd get a 2,5 and if we did 10 / 4 we'd get a 2...but how do i do the \ in C#? i noticed the MOD operator doesnt exist in C# too =\
i saw on msdn and it says the / is overloaded...but how da hell do i do to make that when i want it to have decimal and not decimal then?
When integers are used with arithmetic operators, an integer is returned and any remainder is discarded. When floating-point numbers are used with arithmetic expressions, a floating-point number is returned.
Also, the mod operator is: %Code:static void Main(string[] args)
{
double returnVal = 0;
returnVal = (10 / 4f);
Console.WriteLine(returnVal);
}
what do i do?PHP Code:int iMax = nTab.Width / IMAGE_WIDTH;
MessageBox.Show(iMax.ToString());
You are assigned the result to an integer. Do you want a whole number or floating-point #?
hmm i dont get what u mean...nTab = 777 and IMAGE_WIDTH is 115...i want it to return 6,7565217391304347826086956521739
Code:double dMax = (nTab.Width / IMAGE_WIDTH);
ah it has to be a double?
not working dude :(
Yep, integral numbers discard any decimal values.
what is the return?
ah so 1st i must convert all the values to double right?
is 6 lol
You must be working with integer types. Assign them to double variables.
yea worked now :
isnt there a way that i can do like in vb.net CTYPE(converttype) CTYPE(nTab.Width,wished type) ?PHP Code:double val1 = nTab.Width; double val2 = IMAGE_WIDTH;
double iMax = (val1 / val2);
MessageBox.Show(iMax.ToString());
You will have to cast the variable to the desired type.
( Type Goes Here.. )
Code:double myDouble = (double) nTab.Width;
ah casting is the equivalent to the VB Ctype()?
That's what CType() does..It converts a variables type to a different type.
yea but i didnt know casting was the same thing lolol
Here's another way just for reference:
Code:{
int width = 777, height = 100;
float result = ((float)width / (float)height);
Console.WriteLine(result);
}
what the difference between float,double and integer? and longs? and int16 int32 int64?
There are eight integral types you can use to represent whole or integer numbers:
sbyte, byte, short, ushort, int, uint, long, ulong
As you can see, each type has a signed and unsigned version of the type.
Then we have floating-point types. There are three floating-point types you can use to represent floating-point numbers:
floag, double, decimal
These allow for n # of places after the decimal (precision).
thats the theory..but why do ppl use ints and not shorts? or uints? or sbyts?
Well, each types takes up a different amount of memory when stored on the stack. Don't u agree its a waste to store the number 5 into a long when a byte type would suffice?
hmm...int suports how much memory? 32? and this means what? it can handle up to 32 chars?
32 bits, which is equivalent = -2,147,483,647 to 2,147,483,647 (signed)
isnt there a table around there to see from where to where go that values lol?
Yeah, I'm actually getting ready to leave for a costume party, so do a search and I'm sure you'll find all your looking for.
yea i believe so tks