Controlling the Order of Precedence

Sometimes you want to override the order of precedence. For example, suppose you want to create an expression that calculates the pre-tax cost of an item. If you bought something for $10.65, including 7 percent sales tax, and you wanted to find the cost of the item less the tax, you'd use the expression 10.65/1.07, which gives you the correct answer of $9.95. In general, the expression to use is given by the formula shown in Figure 4.2.

Figure 4.2

A formula for calculating the pre-tax cost of an item.

Figure 4.2

A formula for calculating the pre-tax cost of an item.

Listing 4.1 shows a function that attempts to implement this formula.

0 0

Post a comment