• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 136
  • Last Modified:

Division by zero error

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
Junni
Asked:
Junni
  • 3
  • 3
  • 2
  • +3
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
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
 
JunniAuthor Commented:
the M0_50 should be rounded down, not up..they told me that the \ does that, and the / rounds up !??
0
 
Éric MoreauSenior .Net ConsultantCommented:
\ 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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
JunniAuthor Commented:
the M0_50 should be rounded down, not up..they told me that the \ does that, and the / rounds up !??
0
 
JunniAuthor Commented:
what does the clng(MRest) ?
0
 
Éric MoreauSenior .Net ConsultantCommented:
it converts MRest as a long (it removes the decimals).
0
 
supunrCommented:
M0_50 = CInt(MRest / CDec(0.5))

0
 
supunrCommented:
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
 
Arthur_WoodCommented:
easier, and faster:

M0_50 = CInt(MRest * 2.)
0
 
GunsenCommented:
"They told me", sounds like homework.
You have to tell what you want the algoritm to do?

Emorau has best answer so far...
0
 
mlmccCommented:
M0_50 = CInt(MRest * 2.0 -0.5)

will round down

mlmcc
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now