Question: You use the number_format() function when you want to format the appearance of a number. Th e number_format() function adds commas that separate thousands and
You use the number_format() function when you want to format the appearance of a number. Th e number_format() function adds commas that separate thousands and determines the number of decimal places to display. You can pass two arguments to the number_format() function: Th e rst argument represents the literal number or variable you want to format, and the second argument determines the number of decimal places to display. If you exclude the second argument, the number is formatted without decimal places.
In this project, you will create a script that demonstrates how to use the number_format() function.
1. Create a new document in your text editor.
2. Type the declaration, element, header information, and
element. Use the strict DTD and Single Family Home as the content of the3. Add the following standard PHP script delimiters to the document body:
4. Add the following statements to the script section. Th e rst statement assigns an integer value to a variable named $SingleFamilyHome. Th e second statement then formats the value in the $SingleFamilyHome variable and assigns the formatted number to the $SingleFamilyHome_Print variable. Th e number in the $SingleFamilyHome_Print variable will include a comma that separates the thousands and will include two decimal places. Th e nal statement displays the formatted number on the screen. $SingleFamilyHome = 399500; $SingleFamilyHome_Display = number_format($SingleFamilyHome, 2); echo "
The current median price of a single family home in Pleasanton, CA is $$SingleFamilyHome_Display.
";5. Save the document as SingleFamilyHome.php in the Projects folder for Chapter 1, upload the document to the server, and then validate it with the W3C XHTML Validator. After the document is valid, close it in your text editor, and then open it in your Web browser to see how it renders. You should see the text Th e current median price of a single family home in Pleasanton, CA is $399,500.00. displayed on the screen.
6. Close your Web browser window.
This is for PHP PROGRAMMING WITH SQL.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
