You might want to allow users to enter measurements in fractions, most likely of inches. So a user might want to enter the width of an item as 5 and 1/8 inches. You can then use these measurements to calculate the price of a product.
There’s an example product here showing this in action.
To allow the user to enter measurements in fractions:
- First create a standard number field for your first dimension, e.g. ‘Width’, for the user to enter the whole number
- Then create a select field with the different fractions as the options – e.g. 1/8, 1/4, etc.
- Enter the decimal equivalent of the fraction, e.g. 0.125, 0.25, etc, in the ‘Price’ column next to the fractions
- Finally, set ‘Field Price Visibility’ and ‘Option Price Visibility’ to ‘Hidden’
You can repeat for any further dimensions – e.g. height.
Using fractions in calculations
You can now use the decimal values for the fields in your calculations. Create a calculation field to work out the value of your ‘width’ fields as a decimal:
Note that the formula looks like this:
{field_1752} + {field_1753_option_price}
You will need to change the field IDs to match yours. We use the {field_1753_option_price}
tag to get the decimal value for the fractions.
You can also set this field to ‘Hide Calculation’ so that it’s not displayed on the front end. Also, ensure that you set the ‘Decimal Places’ to the create number.
Repeat this for your ‘height’ field.
Calculating the area
Now you can create a field to set the area. This will just multiply the value of your two calculation fields above.
The formula will be:
{field_2796} * {field_2797}
You will need to change the field IDs to match your own IDs.