In This Topic
Using Rates
How can I use rates in formula and Friendly Pages?
When writing formula or designing Friendly Pages, you will frequently find that you need to deal with rates, such as "dollars per square metre". Without direct support for rates as a builtin type, the only practical way to implement this is by storing the rate as a variable of the "number" type. This doesn't work in some cases, for example:
Calculate the price for 5 square metres of material, which costs $12.50 per square metre. If the rate $12.50/sqm is stored only as a number, the result will be "5 sqm x 12.50". So CabMasterPro will produce a cost of "62.50 sqm", which is obviously not what is required. But this is actually the correct answer to this formula.
CabMasterPro supports "rate" as a type of formula, but using this on a Friendly Page means that the user still has to enter the full number including units, such as "$12.50/sqm" when they only should be expected to enter the number. To work around this, you can create an intermediate value on the "All Answers" list, which takes the value and multiplies it by the appropriate rate. Specifically:
- Leave the existing question on the Friendly Page as type "number". For this example, the name of the value can be "cost_per_metre"
- Change to the "All Answers" tab and create a new variable called, say, "metre_cost_rate"
- Set the type of this new variable to "rate"
- For its formula, enter "cost_per_metre / sqm"
This last step does not actually change the value as it is simply multiplying it by one, but it will make it a proper rate. You can now use this new variable in any formulas you want, and it will work correctly when multiplied with other values of the right type.