Support rational numbers for ingredient values
Rationale:
- People write recipe ingredients like ½ a liter of water.
- Setting a number of servings can lead to fractions with an infinite or impractical number of digits like 1/3 = 0.3333… or 1/256 = 0.00390625
Idea:
- save rational number for value
- existing floating point numbers can be converted
- add denominator 1
- maybe detect rationale values like 1/3???
- allow entering numbers like 0.001 and save as 1/1000→display as 0.001 again (maybe add a boolean column indicating decimal fractions?)
- allow entering numbers like 1/3, save and display as 1/3
Implementation details:
- Raku would offer a native type
Rat
- Perl5 offers
-
Math::BigRat
in core since Perl 5.8.0 -
Number::Fraction
from CPAN
-
- SQLite doesn’t offer any rational number type
- for PostgreSQL there’s an extension pg_rational
- Suggestion:
- use two column for storage and inflate a rational number object when building a DBIx-Class Result object like for DateTime objects
- maybe add a third column with an approximate float value for SQL operations like sorting??
Edited by Daniel Böhmer