開発環境
- OS X Lion - Apple(OS)
- Apache (Web Server)
- PHP (サーバーサイドプログラミング言語)
- TextWrangler(Text Editor) (BBEditの無料機能制限版、light版)
『初めてのPHP5』 (David Sklar 著、 桑村 潤 翻訳、 廣川 類 翻訳、 オライリー・ジャパン、2005年、ISBN978-4-87311-257-2)の2章(テキストと数の操作)2.5(演習問題)3を解いてみる。
3.
コード(TextWrangler)
<?php $h = 4.95; $c = 1.95; $cola = 0.85; $vat = 0.075; $t = 0.16; $hn = 2; $cn = 1; $colan = 1; $sum = $h * $hn + $c * $cn + $cola * $colan; $result = $sum + floor($sum * $vat * 100) / 100 + floor($sum * $t * 100) / 100; print "<pre>"; printf("%-25s %1d \$%.2f\n", "hamburger", $hn, $h*$hn); printf("%-25s %1d \$%.2f\n", "milk", $cn, $c * $cn); printf("%-25s %1d \$%.2f\n", "cola", $colan, $cola * $colan); printf("%-25s \$%.2f\n", "total", $sum); printf("%-25s \$%.2f\n", "vat", floor($sum * $vat * 100) / 100); printf("%-25s \$%.2f\n", "tip", floor($sum * $t * 100) / 100); printf("%-25s \$%.2f\n", "total + vat + tip", $result); print "</pre>"; ?>
HTMLソース
<pre> hamburger 2 $9.90 milk 1 $1.95 cola 1 $0.85 total $12.70 vat $0.95 tip $2.03 total + vat + tip $15.68 </pre>
0 コメント:
コメントを投稿