Lesson 12 of Module 4 in the iOS Foundations course from CodeWithChris deals with putting the mathematical formula into the recipe app so that the app will display the correct portion sizes depending on how many servings the user requires.
I have to admit that I would have arranged the data in other ways to reach this result, but it’s interesting to see how other people handle their data.
In the example we’re working on, portion sizes are presented as a numerator and denominator from which we create a fraction (which may be an improper fraction), multiply it by the chosen serving size, then reformat the fraction into a more readable form.
If this data was retrieved from an external third party, I can’t envisage a situation whereby the numerator and denominator would be presented as separate values. Likewise, if it was me providing the data, I’d stick with decimals for the calculation and do the “formatting for human eyes” at the last point. Separating the numerator and denominator seems unnecessarily cumbersome to me.
But it is intriguing to see how other people approach situations like this.