Re: Missing a Frac() function

Johnny Rosenberg <[email protected]> Mon, 8 Aug 2011 16:45:54 +0200
Newsgroups gmane.comp.openoffice.devel.api
Message-ID <CADo7T4fB=tkDJDcqTd8K1num_syf2ErwfSVCiNpNTkR1QCuv1A@mail.gmail.com>
2011/8/8 Christoph Jopp <[email protected]>:
> Am 08.08.2011 12:28, schrieb Johnny Rosenberg:
>> 2011/8/8 Christoph Jopp <[email protected]>:
>>> Hi Johnny,
>>>
>>> Am 07.08.2011 16:55, schrieb Johnny Rosenberg:
>>>> Am I the only one who miss a Frac() function in OpenOffice.org Basic
>>>> and as a cell function?
>>>>
>>>> I always have to use my own function, which is probably slower than a
>>>> built in function would be:
>>>>
>>>> Function Frac(Value As Double) As Double
>>>> =C2=A0 =C2=A0 Frac=3DValue-Fix(Value) ' Using =E2=80=9DInt=E2=80=9D in=
stead of =E2=80=9DFix=E2=80=9D doesn't work
>>>> properly for negative values.
>>>> End Function
>>>>
>>>> For example, Frac(-12.3456789) =E2=87=A8 -0.3456789
>>>>
>>>> I use Frac() all the time and I can't be the only one who need it, can=
 I? Among
>>>> other things it's nice for separating time from time+date, even if the=
re are
>>>> other ways to do that.
>>>>
>>>> In case there is a Frac() function after all, what's it called?
>>>
>>> The only built-in formula that comes to my mind is
>>> REST(Dividend;Divisor) in German. In English this should be
>>> MOD(Dividend;Divisor).
>>
>> I'm Swedish and it's REST in Swedish too=E2=80=A6 There is a web page
>> somewhere (http://www.probabilityof.com/excel.shtml#30) with
>> translations from Excel (and therefore also
>> OpenOffice.org/LibreOffice) cell function names in English to Swedish
>> and Norwegian, so giving me the English function names is always OK.
>>
>>> But it still has the Problem with the sign of
>>> the Dividend.
>>> For example:
>>> The number in Cell B2 is 4.3459234, your formula should be =3DMOD(B2;1)
>>> The number in B2 is 4.3459234, then the formula should be =3DMOD(B2;-1)
>>>
>>> To overcome this you could use the built-in formula VORZEICHEN(), in
>>> English SIGN().
>>> =C2=A0In the example:
>>> =3DMOD(B2;SIGN(B2)
>>
>> Thanks, works great!
>> =3DREST(B2;TECKEN(B2))
>>
>> But still, there is nothing like that for OpenOffice.org Basic, is it?
>> There is Mod, but it returns an Integer=E2=80=A6! So 12.3456789 Mod 1 re=
turns
>> 0. Not very useful in this case=E2=80=A6
>
> No, the "Basic Mod" behaves different. But you can call the built-in
> formula from Calc as in Koheis snippet:
> http://codesnippets.services.openoffice.org/Calc/Calc.UsingBuiltinFunctio=
ns.snip
>
> And so you get (without much sense in this context):
>
>
> Function getRest( d As Double )
> =C2=A0 svc =3D createUnoService( "com.sun.star.sheet.FunctionAccess" )
> =C2=A0 arg =3D array( d, Sgn(d))
> =C2=A0 getRest =3D svc.callFunction( "MOD", arg )
> End Function

I guess I'll stick with my own Frac function then, since it's more
straight forward and easier to understand. And shorter=E2=80=A6

Function Frac(Value As Double) As Double
 =C2=A0 =C2=A0 Frac=3DValue-Fix(Value)
End Function

Kind regards

Johnny Rosenberg
=E3=82=B8=E3=83=A7=E3=83=8B=E3=83=BC=E3=83=BB=E3=83=AD=E3=83=BC=E3=82=BC=E3=
=83=B3=E3=83=90=E3=83=BC=E3=82=B0

>
>
> Again just another way. It might be more helpful for more complex
> Calc-Formulas. (Here you must use the english names of the formulas)
> ;-)
>
>>
>>> Not really an improvement, just another way.
>>>
>>> Maybe it helps you anyway.
>>>
>>> Christoph
>>
>> Well, it didn't help much in this case, but at least I learned
>> something, which I appreciate! =E2=98=BA
>>
>>
>> Best regards
>>
>> Johnny Rosenberg
>> =E3=82=B8=E3=83=A7=E3=83=8B=E3=83=BC=E3=83=BB=E3=83=AD=E3=83=BC=E3=82=BC=
=E3=83=B3=E3=83=90=E3=83=BC=E3=82=B0
>
> --
> -----------------------------------------------------------------
> To unsubscribe send email to [email protected]
> For additional commands send email to [email protected]
> with Subject: help
>
--=20
-----------------------------------------------------------------
To unsubscribe send email to [email protected]
For additional commands send email to [email protected]
with Subject: help