?
Solved

Division by zero error

Posted on 2003-03-29
11
Medium Priority
?
134 Views
Last Modified: 2012-05-04
I get a "division by zero" error on this line:

M0_50 = MRest \ CDec(0.5)

M0_50 is declared as Integer and MRest as Double

Any idea ?
0
Comment
Question by:Junni
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +3
11 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 8230243
the \ is the integer division. You may want to use /.

or since you divide by .5, you may multiply by 2 to get the same result.
0
 

Author Comment

by:Junni
ID: 8230259
the M0_50 should be rounded down, not up..they told me that the \ does that, and the / rounds up !??
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 8230269
\ is an integer division (you won't get any decimals with it)

/ is a real division.

maybe you should use m0_50 = clng(MRest)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Junni
ID: 8230271
the M0_50 should be rounded down, not up..they told me that the \ does that, and the / rounds up !??
0
 

Author Comment

by:Junni
ID: 8230276
what does the clng(MRest) ?
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 8230279
it converts MRest as a long (it removes the decimals).
0
 
LVL 11

Expert Comment

by:supunr
ID: 8230625
M0_50 = CInt(MRest / CDec(0.5))

0
 
LVL 11

Accepted Solution

by:
supunr earned 150 total points
ID: 8230628
M0_50 = CInt(MRest / CDec(0.5)) ' use this if you want the value to round to the closes integer

M0_50 = Int(MRest / CDec(0.5)) ' use this if you want only the integer part of the division, decimal will be ignored.
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 8231319
easier, and faster:

M0_50 = CInt(MRest * 2.)
0
 
LVL 3

Expert Comment

by:Gunsen
ID: 8231580
"They told me", sounds like homework.
You have to tell what you want the algoritm to do?

Emorau has best answer so far...
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 8231678
M0_50 = CInt(MRest * 2.0 -0.5)

will round down

mlmcc
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month9 days, 11 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question