|
-
Oct 26th, 2002, 04:11 PM
#1
Thread Starter
yay gay
division?
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 =\
-
Oct 26th, 2002, 04:20 PM
#2
Thread Starter
yay gay
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?
-
Oct 26th, 2002, 04:21 PM
#3
PowerPoster
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.
Code:
static void Main(string[] args)
{
double returnVal = 0;
returnVal = (10 / 4f);
Console.WriteLine(returnVal);
}
Also, the mod operator is: %
-
Oct 26th, 2002, 04:22 PM
#4
Thread Starter
yay gay
PHP Code:
int iMax = nTab.Width / IMAGE_WIDTH;
MessageBox.Show(iMax.ToString());
what do i do?
-
Oct 26th, 2002, 04:25 PM
#5
PowerPoster
You are assigned the result to an integer. Do you want a whole number or floating-point #?
-
Oct 26th, 2002, 04:26 PM
#6
Thread Starter
yay gay
hmm i dont get what u mean...nTab = 777 and IMAGE_WIDTH is 115...i want it to return 6,7565217391304347826086956521739
-
Oct 26th, 2002, 04:28 PM
#7
PowerPoster
Code:
double dMax = (nTab.Width / IMAGE_WIDTH);
-
Oct 26th, 2002, 04:28 PM
#8
Thread Starter
yay gay
ah it has to be a double?
-
Oct 26th, 2002, 04:30 PM
#9
Thread Starter
yay gay
not working dude
-
Oct 26th, 2002, 04:30 PM
#10
PowerPoster
Yep, integral numbers discard any decimal values.
-
Oct 26th, 2002, 04:31 PM
#11
PowerPoster
-
Oct 26th, 2002, 04:31 PM
#12
Thread Starter
yay gay
ah so 1st i must convert all the values to double right?
-
Oct 26th, 2002, 04:31 PM
#13
Thread Starter
yay gay
-
Oct 26th, 2002, 04:34 PM
#14
PowerPoster
You must be working with integer types. Assign them to double variables.
-
Oct 26th, 2002, 04:36 PM
#15
Thread Starter
yay gay
yea worked now :
PHP Code:
double val1 = nTab.Width; double val2 = IMAGE_WIDTH;
double iMax = (val1 / val2);
MessageBox.Show(iMax.ToString());
isnt there a way that i can do like in vb.net CTYPE(converttype) CTYPE(nTab.Width,wished type) ?
-
Oct 26th, 2002, 04:40 PM
#16
PowerPoster
You will have to cast the variable to the desired type.
( Type Goes Here.. )
Code:
double myDouble = (double) nTab.Width;
-
Oct 26th, 2002, 04:40 PM
#17
Thread Starter
yay gay
ah casting is the equivalent to the VB Ctype()?
-
Oct 26th, 2002, 04:41 PM
#18
PowerPoster
That's what CType() does..It converts a variables type to a different type.
-
Oct 26th, 2002, 04:42 PM
#19
Thread Starter
yay gay
yea but i didnt know casting was the same thing lolol
-
Oct 26th, 2002, 05:21 PM
#20
PowerPoster
Here's another way just for reference:
Code:
{
int width = 777, height = 100;
float result = ((float)width / (float)height);
Console.WriteLine(result);
}
-
Oct 26th, 2002, 05:22 PM
#21
Thread Starter
yay gay
what the difference between float,double and integer? and longs? and int16 int32 int64?
-
Oct 26th, 2002, 05:29 PM
#22
PowerPoster
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).
-
Oct 26th, 2002, 05:30 PM
#23
Thread Starter
yay gay
thats the theory..but why do ppl use ints and not shorts? or uints? or sbyts?
-
Oct 26th, 2002, 05:34 PM
#24
PowerPoster
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?
Last edited by Lethal; Oct 26th, 2002 at 05:43 PM.
-
Oct 26th, 2002, 05:35 PM
#25
Thread Starter
yay gay
hmm...int suports how much memory? 32? and this means what? it can handle up to 32 chars?
-
Oct 26th, 2002, 05:43 PM
#26
PowerPoster
32 bits, which is equivalent = -2,147,483,647 to 2,147,483,647 (signed)
-
Oct 26th, 2002, 05:44 PM
#27
Thread Starter
yay gay
isnt there a table around there to see from where to where go that values lol?
-
Oct 26th, 2002, 05:46 PM
#28
PowerPoster
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.
-
Oct 26th, 2002, 05:48 PM
#29
Thread Starter
yay gay
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|