8 Replies Latest reply on May 20, 2016 5:00 PM by user24799

    Best way to split the quantity on a restaurant check three ways (1/3 each)?

    user24799

      Three people come into a restaurant and order 4 pitchers of beer at $10.00 each. They ask for separate checks.

       

      I am trying to figure out the best way to display the quantity to the customer. Ideally I would like to show them the quantity as "1 1/3".

       

      I found a custom function that converts decimals to fractions but it's returning "1 21/64".

       

      Can someone please explain how to resolve this issue?

       

      Thanks.

        • 1. Re: Best way to split the quantity on a restaurant check three ways (1/3 each)?
          schamblee

          Convert Decimal to Fraction.  This is computing just the fraction.  

          A whole is 100

          Number of people - divide the whole :  TheNumber = 3

          Convert to decimal :    100/TheNumber    //from your example would be 33.33

          The Numerator : would be 1   //one whole picture of beer

          The  Denominator : would be 100/TheDecimal  //from your example 3

          The Fraction is a text calculation :  Numerator &"/"&Denominator

          • 2. Re: Best way to split the quantity on a restaurant check three ways (1/3 each)?
            crw030

            What about solving this in a different way?  Since I mostly work in a recurring revenue (monthly charges) environment, maybe treat each guest check as a separate invoice line?  And then printout "invoices" ?

             

            Example 1 - even split to 3 guests, but handling guest specific charges

            Stock                Qty   Unit Price   Guest Number

            ===========  ==== ========  ============

            Draft Pitcher          4      $ 10.00          All

            Nachos                  1        $ 5.50            1

            .

            Total:                                $45.50

             

            Split Check (by guest)     <-- could this be common scenarios like "evenly up to 10", "by guest", "single payer"

            Individual Total (1 of 3):    33%             $18.83

            Individual Total (2 of 3):    33%             $13.33

            Individual Total (3 of 3):    33%             $13.34

             

            Example 2 - even split to 3 guests

            Stock                Qty   Unit Price

            ===========  ==== =========

            Draft Pitcher          4      $ 10.00

            Nachos                  1        $ 5.50

            .

            Total:                               $45.50

             

            Split Check (evenly 3)

            Individual Total (1 of 3):    33%             $15.16

            Individual Total (2 of 3):    33%             $15.16

            Individual Total (3 of 3):    33%             $15.17

            • 3. Re: Best way to split the quantity on a restaurant check three ways (1/3 each)?
              user24799

              schamblee wrote:

               

              Convert Decimal to Fraction. This is computing just the fraction.

              A whole is 100

              Number of people - divide the whole : TheNumber = 3

              Convert to decimal : 100/TheNumber //from your example would be 33.33

              The Numerator : would be 1 //one whole picture of beer

              The Denominator : would be 100/TheDecimal //from your example 3

              The Fraction is a text calculation : Numerator &"/"&Denominator

               

              Sorry to be so dense but I am still doing something wrong.

               

              I am not following what you mean here: Number of people - divide the whole : TheNumber = 3

               

              Can you please show me the filemaker formula that I would use to convert .6666666666 to be displayed as 2/3?

              • 4. Re: Best way to split the quantity on a restaurant check three ways (1/3 each)?
                realgrouchy

                I think this is being significantly overthought. No mucking about with decimals is necessary at all, much less converting between decimals and fractions!

                 

                If you want to evenly divide the bill, or a portion thereof, and display the result as a fraction, you'll always want to divide by the number of people. Are you familiar with the MOD function?

                 

                Here I've worked through this bit by bit so you (hopefully) understand how and why I arrived at the formula at the end. I'm sure my old math teacher would be proud.

                 

                p = number of people

                n = number of items to be divided

                S = share of n to each person (whole number only)

                s = share of n to each person (fraction only)

                 

                Case 1: Assume n > p (e.g. 8 pitchers, 3 people)

                n / p = 8 / 3

                n / p = 2.66...

                 

                But you want to show that as 2 2/3. Note that Mod ( n ; p ) = 2

                S = ( n - mod ( n ; p ) ) / p

                S = ( 8 - mod ( 8 / 3 ) ) / 3

                S = ( 8 - 2 ) / 3

                S = 6 / 3

                S = 2

                 

                Then you need to add the fraction to that.

                The numerator is the remainder, and the denominator is the number of people:

                s = mod ( n ; p ) & "/" & p

                s = mod ( 8 / 3 ) & "/" & 3

                s = 2 & "/" & 3

                s = "2/3"

                 

                Put the two together, connected by a space, and:

                S&s = S & " " & s

                S&s = ( n - mod ( n ; p ) ) / p & " " & mod ( n ; p ) & "/" & p

                ...

                S&s = "2 2/3"


                This yields a problem if there are fewer items than people:

                 

                Case 2: Assume n < p (e.g. 3 pitchers, 4 people)

                S&s = 0 3/4

                 

                Add an if statement on S to only show the whole number if greater than zero:

                 

                S&s = If ( ( n - mod ( n ; p ) ) ≠ 0 ; ( n - mod ( n ; p ) ) / p & " " ; "" ) & mod ( n ; p ) & "/" & p

                S&s = "" & mod ( n ; p ) & "/" & p

                S&s = 3/4

                 

                There is also a problem if the number of people divides evenly into the number of items:

                 

                Case 3: There is an even number of people (e.g. 6 pitchers, 3 people)

                S&s = 2 0/3

                 

                Add an if statement on s to only show the fraction if the numbers are different:

                 

                S&s = If ( ( n - mod ( n ; p ) ) ≠ 0 ; ( n - mod ( n ; p ) ) / p & " " ; "" ) & If ( mod ( n ; p ) ≠ 0 ; mod ( n ; p ) & "/" & p ; "" )

                S&s = 2

                 

                (You could add a separate if statement for the connecting space if you wanted, but it's probably of no consequence to have a trailing space on S.

                 

                Lastly, we need to deal with simplifying the resulting fraction:

                 

                Case 4: The fraction needs to be simplified (e.g. 10 pitchers, 6 people)

                Ss = 1 4/6

                 

                I'm not sure the easiest way to simplify fractions, but this one using a "maxfactor" variable works up to a point, and you could expand it if you plan to have even larger groups by adding more values to the calculation to get the maxfactor variable:

                 

                I'll set some variables to make things easier:

                n = 10

                p = 6
                nu = mod ( n ; p ) // nu = numerator

                maxfactor = Max (

                  If ( ( Mod ( nu ; 1 ) = 0 ) and ( Mod ( p ; 1 ) = 0 ) ; 1 ; 0 ) ;

                  If ( ( Mod ( nu ; 2 ) = 0 ) and ( Mod ( p ; 2 ) = 0 ) ; 2 ; 0 ) ;

                  If ( ( Mod ( nu ; 3 ) = 0 ) and ( Mod ( p ; 3 ) = 0 ) ; 3 ; 0 ) ;

                  If ( ( Mod ( nu ; 4 ) = 0 ) and ( Mod ( p ; 4 ) = 0 ) ; 4 ; 0 ) ;

                  If ( ( Mod ( nu ; 5 ) = 0 ) and ( Mod ( p ; 5 ) = 0 ) ; 5 ; 0 )

                  )

                 

                 

                The bolded part below replaces the unbolded part on the right half of Case 3 above.

                 

                S&s = S & If ( mod ( n ; p ) ≠ 0 ; nu / maxfactor & "/" & p / maxfactor ; "" )

                S&s = S & If ( mod ( n ; p ) ≠ 0 ; mod ( n ; p ) / maxfactor & "/" & p / maxfactor ; "" )

                  note: maxfactor = 2

                S&s = S & If ( true ; mod ( 10 ; 6 ) / 2 & "/" & 6 / 2 ; "" )

                S&s = S & mod ( 10 ; 6 ) / 2 & "/" & 6 / 2

                S&s = S & 4 / 2 & "/" & 6 / 2

                S&s = S & 2 & "/" 3

                S&s = ( 1 & " " ) & "2/3"

                S&s = "1 2/3"

                 

                 

                I think that covers all cases.

                 

                Time to put this all together into one calculation:

                Let (

                [

                n = $n ; // number of items purchased

                p = $p ; // number of people

                nu = Mod ( n ; p ) ; // nu = numerator for "Maxfactor" function

                maxfactor = Max (

                If ( ( Mod ( nu ; 1 ) = 0 ) and ( Mod ( p ; 1 ) = 0 ) ; 1 ; 0 ) ;

                If ( ( Mod ( nu ; 2 ) = 0 ) and ( Mod ( p ; 2 ) = 0 ) ; 2 ; 0 ) ;

                If ( ( Mod ( nu ; 3 ) = 0 ) and ( Mod ( p ; 3 ) = 0 ) ; 3 ; 0 ) ;

                If ( ( Mod ( nu ; 4 ) = 0 ) and ( Mod ( p ; 4 ) = 0 ) ; 4 ; 0 ) ;

                If ( ( Mod ( nu ; 5 ) = 0 ) and ( Mod ( p ; 5 ) = 0 ) ; 5 ; 0 ) ) ;

                W = ( n - Mod ( n ; p ) ) / p ;

                f = nu / maxfactor & "/" & p / maxfactor

                ]

                ;

                If ( ( n - nu ) ≠ 0 ; W ; "" )  // whole number component, if ≠ 0

                & If ( ( ( n - nu ) ≠ 0 ) and ( nu ≠ 0 ) ; " " ; "" ) // separator, if there is both a whole number and fractional component

                & If ( nu ≠ 0 ; f ; "" ) // fractional component, if ≠ 0

                )

                 

                Note:

                - The result is text, not a number, but I suspect that's what you want since you can simply use "n/p" as a multiplier with the Round () function to calculate prices.

                - I changed S and s to W and f for Whole and fraction because FM didn't like S and s

                - $n and $p can be defined as variables (as I did for the purposes of testing this formula), or you can simply have them defined as parameters of a custom function of Share ( n ; p ) and dispense with the first two lines.

                 

                If 14 people order 45 items, it'll return the odd fraction "3 3/14" but I can't see any way around that and I suspect that's what you'd want anyway since it is true.

                 

                - RG>

                1 of 1 people found this helpful
                • 5. Re: Best way to split the quantity on a restaurant check three ways (1/3 each)?
                  user24799

                  Wow, thanks so much realgrouchy. Your solution was a tremendous help and I really appreciate your detailed explanation. I have created a custom function with your formula and it's working great.

                  • 6. Re: Best way to split the quantity on a restaurant check three ways (1/3 each)?
                    user24799

                    Thanks guys. I really appreciate everyone's help on this.

                    • 7. Re: Best way to split the quantity on a restaurant check three ways (1/3 each)?
                      erolst

                      Very nice; now if you go more easy on the parentheses and the ≠ 0 …

                       

                      // Fractioner ( i ; p )

                      // creates a fractional expression of i / p

                      Let ( [

                        nu = Mod ( i ; p ) ; // nu = numerator for maxFactor calculation

                       

                        maxFactor =

                          Max (

                            If ( not Mod ( nu ; 1 ) and not Mod ( p ; 1 ) ; 1 ) ;

                            If ( not Mod ( nu ; 2 ) and not Mod ( p ; 2 ) ; 2 ) ;

                            If ( not Mod ( nu ; 3 ) and not Mod ( p ; 3 ) ; 3 ) ;

                            If ( not Mod ( nu ; 4 ) and not Mod ( p ; 4 ) ; 4 ) ;

                            If ( not Mod ( nu ; 5 ) and not Mod ( p ; 5 ) ; 5 ) ;

                            0

                          ) ;

                       

                        w = ( i - Mod ( i ; p ) ) / p ; 

                        f = nu / maxFactor & "/" & p / maxFactor ;

                       

                        theInt =  If ( i - nu ; w ) ; // whole number component, if ≠ 0

                        theFrac = If ( nu ; f ) ; // fractional component, if ≠ 0

                        theSep = If ( theInt and theFrac ; " " ) // separator, if there is both a whole number and fractional component

                        ] ;

                        theInt & theSep & theFrac

                      )

                      2 of 2 people found this helpful
                      • 8. Re: Best way to split the quantity on a restaurant check three ways (1/3 each)?
                        user24799

                        You guys are amazing. This solution is great. One of you guys should post it to Brian Dunnings wonderful site of custom functions.

                         

                        There is a reason why I chose art school.