Archey
Archey

Reputation: 1342

VB.NET Attempted to divide by 0 error when Integer dividing by decimal

I'm trying to do Integer division () by 0.25 but VB is telling me I tried to divide by zero, I also tried dividing by (1/4).

This is my snippet

AmountLeft = Remainder \ 0.25
lblQuartersAmount.Text = AmountLeft

Upvotes: 3

Views: 1656

Answers (1)

Ry-
Ry-

Reputation: 225164

You can't do integer division by a non-integer; just truncate and cast it afterwards.

AmountLeft = CInt(Math.Truncate(Remainder / 0.25))

And what's wrong with * 4? =)

Upvotes: 2

Related Questions