Bug 100593 - Add fraction number format option to reduce forced denominator
Summary: Add fraction number format option to reduce forced denominator
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium enhancement
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Number-Format
  Show dependency treegraph
 
Reported: 2016-06-24 15:42 UTC by Laurent Balland
Modified: 2021-04-26 13:08 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments
Example of forced denominator fraction format (10.48 KB, application/vnd.oasis.opendocument.spreadsheet)
2016-07-04 08:00 UTC, Laurent Balland
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Laurent Balland 2016-06-24 15:42:29 UTC
Description: Fraction number format enables forced denominator, such as ?/4. But in some cases, user would prefer reduced fraction than exact forced denominator.

Steps to reproduce:
1. Change number format: Format > Cells > Numbers, Category: Fraction
2. Enter format such as # ?/4
3. Enter values 0.25, 0.50, 0.75, 1.00, 1.25, 1.50, 1.75, 2.00

Actual behavior:
Display
1/4, 2/4 (!), 3/4, 1, 1 1/4, 1 2/4 (!), 1 3/4, 2

Expected behavior:
Previous display is correct, but user may expect
1/2 instead of 2/4 and 1 1/2 instead of 1 2/4

May be a number format such as # ?/(4) could be ok to have reduced fraction even with forced denominator?
Comment 1 Joel Madero 2016-07-04 05:23:27 UTC
Hi Laurent,

Isn't that just #?/?

I just did that and entered your values and got the results you suggested you wanted to see. For now closing as WFM - if I'm mistaken, apologies and of course toss it back into UNCONFIRMED.
Comment 2 Laurent Balland 2016-07-04 07:03:13 UTC
(In reply to Joel Madero from comment #1)
> Hi Laurent,
> 
> Isn't that just #?/?
> 
> I just did that and entered your values and got the results you suggested
> you wanted to see. For now closing as WFM - if I'm mistaken, apologies and
> of course toss it back into UNCONFIRMED.

Sorry, I was not enough clear. I want *forced* denominator. Format with free denominator "# ?/?" like for your test gives reduced fraction. But format with forced denominator, like "# ?/4" or "# ??/16", cannot reduce the fraction representation.
What I suggest is an option to have reduce fraction with forced denominator:
Example: format "# ??/16" . Value 3.5
- without option  (default behavior) should give "3 8/16"
- with option should give "3 1/2"

I have no clear idea how this option should be set. I may suggest to add a special delimiter at the end of the format, like #. In this case, format would look like "# ??/16#"
Comment 3 Laurent Balland 2016-07-04 08:00:53 UTC
Created attachment 126053 [details]
Example of forced denominator fraction format

(In reply to Joel Madero from comment #1)
> Hi Laurent,
> 
> Isn't that just #?/?

Some more details: "# ?/??" will actually reduce fraction. But, if I want rounded fraction each 1/16 inch for instance, then "# ?/??" will not round each 1/16. See attached example.
Comment 4 Joel Madero 2016-07-06 06:09:23 UTC
(In reply to Laurent BP from comment #3)

> Some more details: "# ?/??" will actually reduce fraction. But, if I want
> rounded fraction each 1/16 inch for instance, then "# ?/??" will not round
> each 1/16. See attached example.

Ah yes I see now.

Confirming

Version: 5.3.0.0.alpha0+
Build ID: 28a03248b1d1649e157b788e43dfe8326f165379
CPU Threads: 2; OS Version: Linux 3.16; UI Render: default; 
Locale: en-US (en_US.UTF-8)
Comment 5 Nadith Malinda 2016-07-29 11:55:31 UTC
@ Laurent BP 
so what you said is implement a new format code like (lets take 16 here this can be change too... no?)
 # ?/16# - which does reduced fraction even with forced denominator

if we choose Format > Cells > Numbers, Category: Fraction as this code

it will give output as you mentioned. as example 
having setup format like you said  # ?/16#
then enter 
3.3125 -> 3 5/16
3.5 -> 3 1/2
3.45 -> 3 7/16
3.25 -> 3 1/4
1.0625 ->1 1/16
Comment 6 Nadith Malinda 2016-07-29 12:01:04 UTC
@ Laurent BP 
so what you said is implement a new format code like (lets take 16 here this can be change too... no?)
 # ?/16# - which does reduced fraction even with forced denominator

if we choose Format > Cells > Numbers, Category: Fraction as this code

it will give output as you mentioned. as example 
having setup format like you said in Format > Cells > Numbers, Category to # ?/16#
then if we enter 
3.3125 -> 3 5/16
3.5    -> 3 1/2
3.45   -> 3 7/16
3.25   -> 3 1/4
1.0625 -> 1 1/16
1.125  -> 1 1/8

simply if if the fraction part can be reduce output should be in  reduced fraction form
if not it should be in forced denominator form. in this case in  x/16 where x is not divided by 16

is that you want....?

if so I would like to try this bug
Comment 7 Eike Rathke 2016-07-29 12:46:57 UTC
First make sure that such a format code can be stored in Excel files without interfering with how Excel interprets it and not makes it complain or throw away when reading. In this example  # ?/16#  is not accepted in Excel UI. Best of course would be if Excel supported denominator reduction with some format code, but I think it doesn't.

Then we'd also need an ODF attribute extension to store such in ODF files.
Comment 8 Laurent Balland 2016-07-29 12:58:01 UTC
(In reply to Nadith Malinda from comment #6)
> is that you want....?
> 
> if so I would like to try this bug

I think you've got it. Yes, 16 was just an example.
If you want to try this bug you may need some entry points:
- calculation of fraction in SvNumberformat::ImpGetFractionOutput
http://opengrok.libreoffice.org/xref/core/svl/source/numbers/zformat.cxx#ImpGetFractionOutput
and for forced denominator
http://opengrok.libreoffice.org/xref/core/svl/source/numbers/zformat.cxx#2464
- scan of format to detect forced denominator in ImpSvNumberformatScan::FinalScan
http://opengrok.libreoffice.org/xref/core/svl/source/numbers/zforscan.cxx#FinalScan
and more precisely
http://opengrok.libreoffice.org/xref/core/svl/source/numbers/zforscan.cxx#1681

But as mentioned by Eike, first step would be to choose a correct coding
Comment 9 Nadith Malinda 2016-08-03 04:00:17 UTC
(In reply to Eike Rathke from comment #7)
> First make sure that such a format code can be stored in Excel files without
> interfering with how Excel interprets it and not makes it complain or throw
> away when reading. In this example  # ?/16#  is not accepted in Excel UI.
> Best of course would be if Excel supported denominator reduction with some
> format code, but I think it doesn't.

As you mentioned I thought How can we do this while supporting Excel.I came up with this idea but i don't know how good/bad that idea is,this is my idea
we used the same format code # ?/16 (since it is accepted) and we put a simple button to toolbar to get the workdone.
if button=true : reduced fraction form activated forced denominator form
if button=false: only forced denominator form


> 
> Then we'd also need an ODF attribute extension to store such in ODF files.

I think then we don't need this extetion.isn't it?
Comment 10 Nadith Malinda 2016-08-03 04:06:13 UTC
(In reply to Laurent BP from comment #8)

> But as mentioned by Eike, first step would be to choose a correct coding

i commented, what I'm thinking to do for this bug as a reply to Eike . if you like it you can assign me for the bug.or if you have any suggestion tell me.I will try my best
Comment 11 Laurent Balland 2016-08-03 07:58:58 UTC
(In reply to Nadith Malinda from comment #10)
> (In reply to Laurent BP from comment #8)
> 
> > But as mentioned by Eike, first step would be to choose a correct coding
> 
> i commented, what I'm thinking to do for this bug as a reply to Eike . if
> you like it you can assign me for the bug.or if you have any suggestion tell
> me.I will try my best

Feel free to assign yourself to this bug if you think you can tackle it :)

You will need to extend ODF for this option because it will be specific for each format, not an option for a user.
If you need, I could guide you for this.
Comment 12 Nadith Malinda 2016-08-03 13:45:58 UTC
(In reply to Laurent BP from comment #11)

> You will need to extend ODF for this option because it will be specific for
> each format, not an option for a user.
> If you need, I could guide you for this.

thank you .yes, I will need your help for ODF,First I will go through all the pointers you have given and try understand.
Comment 13 Xisco Faulí 2016-09-10 22:27:49 UTC
Hi Nadith,
Please, next time you assign a bug to yourself, remember to change the status and the assignee.
Regards
Comment 14 Nadith Malinda 2016-09-18 09:24:24 UTC
(In reply to Xisco Faulí from comment #13)
> Hi Nadith,

Hi.
> Please, next time you assign a bug to yourself, remember to change the
> status and the assignee.

I was out for few days since I was busy with university exams.I would like to try this if you like
Comment 15 Eike Rathke 2016-09-19 09:39:47 UTC
(In reply to Nadith Malinda from comment #14)
> I would like
> to try this if you like

Umm.. try what exactly?
Comment 16 Nadith Malinda 2016-09-19 15:02:27 UTC
(In reply to Eike Rathke from comment #15)

> Umm.. try what exactly?

try this bug(enhancement) to fix it
Comment 17 Xisco Faulí 2017-07-13 09:18:25 UTC
Setting Assignee back to default. Please change it back if you're still working on this issue