Int() problem

Int() problem

Anonymous
Not applicable
392 Views
4 Replies
Message 1 of 5

Int() problem

Anonymous
Not applicable
i am writing code for convert inch to feet. In my code:

feet = Fix(InchesInput \ 12)

the code works fine, except when it comes 11'-11 1/2" (143.5 inches) or 9'-11 1/2" (119.5 inches) etc (as long as 11 1/2"), the result becomes

feet = Fix(119.5\12) = 10??? (instead of 9!!!)
feet = Fix(143.5\12) = 12??? (instead of 11!!!)

How come?? Any suggestion??

thanks,
0 Likes
393 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
stab in the dark.. (new to vba, and not tested)

but.. why have the "fix" at all?.. does that not round off your result?
0 Likes
Message 3 of 5

Anonymous
Not applicable
CRiZ wrote:
> i am writing code for convert inch to feet. In my code:
>
> feet = Fix(InchesInput \ 12)
>
> the code works fine, except when it comes 11'-11 1/2" (143.5 inches) or 9'-11 1/2" (119.5 inches) etc (as long as 11 1/2"), the result becomes
>
> feet = Fix(119.5\12) = 10??? (instead of 9!!!)
> feet = Fix(143.5\12) = 12??? (instead of 11!!!)
>
> How come?? Any suggestion??

You're using \, which is the integer division operator. Operands are
rounded to integers before the division takes place, I believe.

Also, Fix'ing the result of integer division is redundant.

Use the normal division operator: /.

> feet = Fix(119.5\12) = 10??? (instead of 9!!!)

Fix(119.5 \ 12) == (119.5 \ 12) == 10
Fix(119.5 / 12) == 9

HTH,
Adam
0 Likes
Message 4 of 5

Anonymous
Not applicable
? Fix(119.5 / 12)
9

Note the division symbol....they ARE different.

wrote in message news:5026055@discussion.autodesk.com...
i am writing code for convert inch to feet. In my code:

feet = Fix(InchesInput \ 12)

the code works fine, except when it comes 11'-11 1/2" (143.5 inches) or
9'-11 1/2" (119.5 inches) etc (as long as 11 1/2"), the result becomes

feet = Fix(119.5\12) = 10??? (instead of 9!!!)
feet = Fix(143.5\12) = 12??? (instead of 11!!!)

How come?? Any suggestion??

thanks,
0 Likes
Message 5 of 5

Anonymous
Not applicable
You guys are great!! Silly me.

Thanks,!!
0 Likes