Xfce Forum

Sub domains
 

You are not logged in.

#1 2021-05-16 17:16:11

jt1122
Member
Registered: 2021-03-26
Posts: 240

calculator plugin - set # of digits to round

Hi,

In the calculator plugin
https://docs.xfce.org/panel-plugins/xfc … ugin/start
Is there a way to set the number of digits to which results will be rounded?.

For now 1/3 gives 0.3333333333333333 and reducing the number of digits doesn't affect rounding only the visible part.

Thanks

Offline

#2 2021-05-16 18:06:13

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,949

Re: calculator plugin - set # of digits to round

Unfortunately, the output is hard-coded to 16 digits. Interesting, that they are forcing %g to 16 digits - because of its nature it will by default use the shortest representation of %e or %f (Here is a good discussion about this).

Editing that piece of code to specify just "%g" yields better results. For example:
- 1/2 = 0.333333
- pi = 3.14159
- 1/198 = 0.00505051
- 1/19 = 0.0526316


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#3 2021-05-16 18:09:59

jt1122
Member
Registered: 2021-03-26
Posts: 240

Re: calculator plugin - set # of digits to round

Thanks.

If I'm fine with 3 decimal digits should that be changed to %.3f ?

Offline

#4 2021-05-16 20:56:51

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,949

Re: calculator plugin - set # of digits to round

jt1122 wrote:

Thanks.

If I'm fine with 3 decimal digits should that be changed to %.3f ?

If its for your personal use and you will be building and maintaining your own copy of the source, then you can do as you choose.

For the official release, I think it would be best to add functionality to allow the user to specify a rounding value (e.g. round after x decimals).


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#5 2021-05-17 09:11:28

jt1122
Member
Registered: 2021-03-26
Posts: 240

Re: calculator plugin - set # of digits to round

It's for personal use and I'm just modifying to suit my needs. I fully agree rounding should be user controlled.

Is autogen run as configure (with the --prefix and --libdir switches)?. I'm on sparky rolling (=deb testing).

Thanks

Last edited by jt1122 (2021-05-17 09:21:25)

Offline

#6 2021-05-17 10:54:49

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,949

Re: calculator plugin - set # of digits to round

jt1122 wrote:

Is autogen run as configure (with the --prefix and --libdir switches)?. I'm on sparky rolling (=deb testing).

Yes, it should be. And because debian splits the location of the 32 and 64 it library files, you should use something like:

./autogen.sh --prefix=/usr --libdir=/lib/$(uname -m)-linux-gnu

Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

Board footer

Powered by FluxBB