[Solved] Show number as a fixed fraction

Discuss the spreadsheet application
Locked
Kirjava
Posts: 41
Joined: Sun May 03, 2015 2:58 pm

[Solved] Show number as a fixed fraction

Post by Kirjava »

I want it to round to nearest 1/12th to show years & months without having the whole date so that 3.5 years shows as 3 6/12.
Thank you.
Last edited by MrProgrammer on Mon Nov 02, 2026 4:34 pm, edited 2 times in total.
Reason: Tagged ✓ [Solved]; Multiple solutions provided and no further questions from Kirjava
OpenOffice 3.1 on Windows 7
Kirjava
Posts: 41
Joined: Sun May 03, 2015 2:58 pm

Re: Is there a way to show a number as a fixed fraction?

Post by Kirjava »

Ended up doing =TRUNC(B2/1)&"y "&ROUNDDOWN(12*(B2-TRUNC(B2/1)))&"m" to show it but there's probably an easier way. I'll write down the easier way and do that next time. This takes 22.4 and spits out 22y 5m.
OpenOffice 3.1 on Windows 7
User avatar
karolus
Volunteer
Posts: 1252
Joined: Sat Jul 02, 2011 9:47 am

Re: Is there a way to show a number as a fixed fraction?

Post by karolus »

Kirjava wrote: Mon Aug 24, 2026 2:49 pm but there's probably an easier way.
Format B2 into Numberformat-code #"y "??/12 "m"
Libreoffice 25.2… on Debian 13 (trixie) (on RaspberryPI5)
Libreoffice 25.8… flatpak on Debian 13 (trixie) (on RaspberryPI5)
Kirjava
Posts: 41
Joined: Sun May 03, 2015 2:58 pm

Re: Is there a way to show a number as a fixed fraction?

Post by Kirjava »

Format > Cells > Fraction > Pasted [ #"y "??/12 "m" ] into the format box > Click OK > No change.
It reverted back to "general" when I checked again.
What did I do wrong?
OpenOffice 3.1 on Windows 7
User avatar
karolus
Volunteer
Posts: 1252
Joined: Sat Jul 02, 2011 9:47 am

Re: Is there a way to show a number as a fixed fraction?

Post by karolus »

Kirjava wrote: Mon Aug 24, 2026 8:13 pm
What did I do wrong?
nobody knows… see attached Example with a calculated yearfraction formatted the way you want!
yearfrac_formula_and_Formatting.ods
(10.55 KiB) Downloaded 450 times
Libreoffice 25.2… on Debian 13 (trixie) (on RaspberryPI5)
Libreoffice 25.8… flatpak on Debian 13 (trixie) (on RaspberryPI5)
Kirjava
Posts: 41
Joined: Sun May 03, 2015 2:58 pm

Re: Is there a way to show a number as a fixed fraction?

Post by Kirjava »

No it is not.

Your example:
08/05/26 End_date
01/02/24 Start_date
2.2657534247 =YEARFRAC(A2;A1;3)

My example:
24.5 24y 5m
OpenOffice 3.1 on Windows 7
User avatar
karolus
Volunteer
Posts: 1252
Joined: Sat Jul 02, 2011 9:47 am

Re: Is there a way to show a number as a fixed fraction?

Post by karolus »

Kirjava wrote: Tue Aug 25, 2026 12:02 am No it is not.
????
20260825_03h45m27s_grim.png
20260825_03h45m27s_grim.png (32.05 KiB) Viewed 3960 times
Libreoffice 25.2… on Debian 13 (trixie) (on RaspberryPI5)
Libreoffice 25.8… flatpak on Debian 13 (trixie) (on RaspberryPI5)
User avatar
MrProgrammer
Moderator
Posts: 5480
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: Is there a way to show a number as a fixed fraction?

Post by MrProgrammer »

Kirjava wrote: Mon Aug 24, 2026 8:13 pm What did I do wrong?
Your forum signature gives your environment as OpenOffice 3.1 on Windows 7. I am sure OpenOffice 3.1 would not have supported ??/12 in the number format. I doubt that any OpenOffice version does. So karolus' solution is only for LibreOffice. Read about LibreOffice/OpenOffice comparisons in the Beginners forum.

If this solved your problem please go to your first post use the Edit ✏️ button and add [Solved] to the start of the Subject field. Select the green checkmark icon at the same time.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.7.8, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
User avatar
MrProgrammer
Moderator
Posts: 5480
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: Is there a way to show a number as a fixed fraction?

Post by MrProgrammer »

Kirjava wrote: Mon Aug 24, 2026 2:20 pm … fixed fraction …
I don't know what that term means.

Kirjava wrote: Mon Aug 24, 2026 2:20 pm … without having the whole date …
If you don't know the start/end dates, only the duration (in days), you cannot present this as years and rounded months unless you are willing to ignore the detail that months and years have different lengths. As a simple example, a duration of 15 days is less than half of January but more than half of February. But you could consider years to be divided into twelve equal pieces of 30.436875 days. 15 days is less than half of an average month.

INT(duration/30.436875+.5) is the number of months, rounded.
QUOTIENT(months;12) is the number of full (12-month) years.
MOD(months;12) is the number of months which follow those years.

If you need any additional assistance attach a spreadsheet demonstrating the situation (remove confidential information then use Post Reply, not Quick Reply, and don't attach a picture instead of the spreadsheet itself). I will not help further unless you attach a spreadsheet document.

[Tutorial] Ten concepts that every Calc user should know

If this solved your problem please go to your first post use the Edit ✏️ button and add [Solved] to the start of the Subject field. Select the green checkmark icon at the same time.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.7.8, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
User avatar
Lupp
Volunteer
Posts: 3761
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Is there a way to show a number as a fixed fraction?

Post by Lupp »

A variant:
aoo_strangeRounding.ods
(13.81 KiB) Downloaded 558 times
On Windows 10: LibreOffice 25.8.4 and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
Locked