Convert a value into fraction display

Hey all! I work in film, and film people are very set in their ways. Scripts are measured in Page 8ths. Don’t ask me why lol. I have a field to hold how many 1/8ths of a page a scene is, and I need it that way so I can do things like aggregate a days worth of scenes.

But I need the end display on my reports to show in the 8ths. Gemini explains it - but what is the actual formula I would use? Thanks!!

def convert_to_eighths_string(reference_number):
“”"
Converts a reference number (representing eighths) into a string in the format “whole number fraction/8”.

Args:
    reference_number: The number representing the total eighths.

Returns:
    A string representing the number as whole number and fraction of eighths.
"""
whole_number = reference_number // 8  # Integer division to get the whole number
remaining_eighths = reference_number % 8  # Modulo to get the remaining eighths

if remaining_eighths == 0:
    return str(whole_number)  # If no remaining eighths, just return the whole number
else:
    return f"{whole_number} {remaining_eighths}/8"

Example usage:

reference_number = 10
result = convert_to_eighths_string(reference_number)
print(f"{reference_number} eighths = {result}") # Output: 10 eighths = 1 2/8

reference_number = 16
result = convert_to_eighths_string(reference_number)
print(f"{reference_number} eighths = {result}") #Output: 16 eighths = 2

reference_number = 27
result = convert_to_eighths_string(reference_number)
print(f"{reference_number} eighths = {result}") #output: 27 eighths = 3 3/8

1 Like

Hi Shannon,

Welcome to the community!

Here’s the formula you need, where n is the name of the column or control containing the number.

format("{1} {2}/8",RoundDown(n/8,0),n.Remainder(8).Round(0))

Hope this helps,

Pablo

3 Likes

Amazing! Is there a way to have it not display the leading zero (ie 1/8 currently displays 0 1/8) or the fraction if there is zero (ie a full page currently displays 1 0/8)

Even if not, I can work with this and I really appreciate it!

1 Like

Sure, I had obviously not tested it enough :slight_smile:

Concatenate(
  if(RoundDown(n/8,0)=0,"",RoundDown(n/8,0)),
  " ",
  if(n.Remainder(8).Round(0)=0,"",Concatenate(n.Remainder(8).Round(0),"/8"))
).Trim()
4 Likes

You are a genius :slight_smile: This makes my life so much easier (I can never wrap my brain around formulas lol)

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.