The chapter begins by creating an HTML form that will be used to generate number variables. Then you’ll learn how to perform basic arithmetic, how to format numbers, and how to cope with operator precedence. The last two sections of this chapter cover incrementing and decrementing numbers, plus generating random numbers. Throughout the chapter, you’ll also learn about other useful number-related PHP functions.

Chapter 2, “Variables,” briefly discussed the various types of variables, how to assign values to them, and how they’re generally
used. In this chapter, you’ll work specifically with number variables—both integers (whole numbers) and floating-point numbers
(aka floats or decimals).

The chapter begins by creating an HTML form that will be used to generate number variables. Then you’ll learn how to perform
basic arithmetic, how to format numbers, and how to cope with operator precedence. The last two sections of this chapter cover incrementing and decrementing numbers, plus generating random numbers. Throughout
the chapter, you’ll also learn about other useful number-related PHP functions.

Creating the Form

Most of the PHP examples in this chapter will perform various calculations based on an e-commerce premise. A form will take
price, quantity, discount amount, tax rate, and shipping cost , and the PHP script that handles the form will return a total cost. That cost will also be broken down by the number of payments
the user wants to make in order to generate a monthly cost value .

This form tag begins the HTML form. Its action attribute indicates that the form data will be submitted to a page named handle_calc.php. The tag’s method attribute tells the page to use POST to send the data. See Chapter 3, “HTML Forms and PHP,” for more details.

The shipping selection is made using a drop-down menu. The value of the selected option is the cost for that option. If the
user selects, for example, the Put a move on it. option, the value of $_POST['shipping'] in handle_calc.php will be 8.95.