By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,515 Members | 1,042 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,515 IT Pros & Developers. It's quick & easy.

Integer Division Broken?

P: n/a
Ben
Hi, I have an interesting example from my debugger. I have 2 variables:
sourcewidthnet and targetwidthnet. Notice the results in the debugger.
I'm going to be forced to use the int function of the decimal.toint32
since the \ operator doesn't appear to work, or I greatly misunderstand
the documentation on the \ operator.

decimal.Remainder(sourcewidthnet, targetwidthnet) 0.375D
sourcewidthnet 96D
targetwidthnet 2.125D
SourceWidthNet / TargetWidthNet
45.176470588235294117647058824D(SourceWidthNet \ TargetWidthNet)
48 Long
decimal.ToInt32((SourceWidthNet / TargetWidthNet)) 45 Integer

I can't justify the: 96 \ 2.125 = 48 answer at all!

Thanks for your input.

Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
It is correct. 96 \ 2 = 48. When you do an integer division, the divisor
is the integer part, which in this case is 2.

"Ben" <be***********@bankscorporation.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hi, I have an interesting example from my debugger. I have 2 variables:
sourcewidthnet and targetwidthnet. Notice the results in the debugger.
I'm going to be forced to use the int function of the decimal.toint32
since the \ operator doesn't appear to work, or I greatly misunderstand
the documentation on the \ operator.

decimal.Remainder(sourcewidthnet, targetwidthnet) 0.375D
sourcewidthnet 96D
targetwidthnet 2.125D
SourceWidthNet / TargetWidthNet
45.176470588235294117647058824D(SourceWidthNet \ TargetWidthNet)
48 Long
decimal.ToInt32((SourceWidthNet / TargetWidthNet)) 45 Integer

I can't justify the: 96 \ 2.125 = 48 answer at all!

Thanks for your input.

Nov 21 '05 #2

P: n/a
Ben
Ok, I finally see the documentation in the remarks section:

Remarks
Before division is performed, any floating-point numeric expressions
are coerced to Long if Option Strict is Off. If Option Strict is On, a
compiler error results

Silly me, thanks.

Still to get what I'm looking for the int() and decimal.tointxx
routines will work, thanks again.

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.