Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA integer division using Decimal datatype

Tags:

vba

I'm trying to divide a variable x of type Decimal by another Decimal y and get only the integer result, but I'm getting an overflow error.

Dim a As Variant
Dim b As Variant

a = CDec(129801938493)
b = CDec(9385029380)

a = a \ b

Apparently the \ operator coerces its arguments to the Long datatype. Is there a way to do integer division (or modulo division) using Decimal?

like image 560
Joe Avatar asked Dec 05 '25 11:12

Joe


1 Answers

a = Int(a / b)

The Int function truncates, so that should work the same as "\".

like image 70
Dick Kusleika Avatar answered Dec 09 '25 15:12

Dick Kusleika



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!