Am Mittwoch, 14. Dezember 2005 12:21 schrieb Joerg Barfurth:
> >> How do I perform an integer division (e.g. 11 / 3 = 4) in OpenOffice
> >> Basic?
>
> Huh? IME the integer division operator (in languages where it exists)
> would produce 11 div 3 = 3, to match the modulus produced by the 'mod'
> operator (which does exist in StarBasic).

Whoah, a fatal typo.  Here's what I should've written: 11/3 = 3.

> You can get a more typical integer division by using the available
> functions to convert to an integer by rounding down or truncating
>
>   roundeddown% = int(11/3) ' value is 3
>   truncated% = fix(11/3)   ' value is 3
>
> These differ when negative numbers are involved. AFAICT truncation is
> the one that matches the builtin MOD operator, ie.
>
>    b*fix(a/b) + a mod b = a

Well, I guess that all of these use floating point numbers as an intermediary, 
something I do *not* want.

-- 
Dipl.-Phys. Felix E. Klee
Email: [EMAIL PROTECTED] (work), [EMAIL PROTECTED] (home)
Tel: +49 721 8307937, Fax: +49 721 8307936
Linuxburg, Goethestr. 15A, 76135 Karlsruhe, Germany

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to