I am trying to: Enter a decimal value into a numeric field
Where the issue can be seen: Creating a new record in admin for a CPT (ingredients)
Questions:
1. How are decimal values entered into numeric fields? I am using the Types Beta 2.3-b5 version.
2. How can numbers be entered by the user as a fraction?
3. How can decimal values be displayed to the user as a fraction?
Example:
I am developing a website that contains recipes. A recipe is related to ingredients. An ingredient might be 1/4 cup oil.
Future capability support:
A recipe can be sized to create 4 servings. If servings are increased to 8 I will need to perform math functions to increase the ingredient quantities.
1. How are decimal values entered into numeric fields? I am using the Types Beta 2.3-b5 version.
The value must start with a number, so in your example above it should be entered as 0.25
2. How can numbers be entered by the user as a fraction?
One option is to create a select field with each fraction listed in text, and its value predefined as a decimal. For example, the options could be as follows:
Text: 1/2, Value: 0.5
Text: 1/3, Value: 0.333333
Text: 1/4, Value: 0.25
Text: 1/8, Value 0.125
Text: 2/3, Value: 0.666666
Text: 3/4, Value: 0.75
Text: 3/8, Value: 0.375
Text: 5/8, Value: 0.625
Text: 7/8, Value: 0.875
...
and so on. This will allow you to capture decimals, which can be used for calculations in code, while displaying fractions for your visitors.
3. How can decimal values be displayed to the user as a fraction?
There isn't a simple answer for displaying decimals as fractions in HTML, and there are different approaches:
hidden link
Where it gets tricky is in the future support for calculations. You'll want to use decimal values to perform those calculations, but then you probably want to convert those back to fractions to display to your visitors. My guess is this will require a significant amount of custom code. Toolset isn't really designed to help with mathematical calculations, so we don't have many built-in tools to do this type of conversion. Here's a quick search result: https://stackoverflow.com/questions/1954018/php-convert-decimal-into-fraction-and-back
We do have a portal available where you can connect with skilled developers who may be able to assist with this type of programming. You can find that portal here: https://toolset.com/contractors/
It seems that using a Select field would be the simplest solution. This opens up another question so I will create a new ticket. Thank you for your quick response.