TAILIEUCHUNG - Học php, mysql và javascript - p 16

hiết lập độ chính xác Không chỉ bạn có thể chỉ định một loại chuyển đổi, bạn cũng có thể thiết lập độ chính xác của kết quả hiển thị. Ví dụ, các khoản tiền thường được hiển thị với hai chữ số của độ chính xác. | Precision Setting Not only can you specify a conversion type you can also set the precision of the displayed result. For example amounts of currency are usually displayed with only two digits of precision. However after a calculation a value may have a greater precision than this such as 12 which results in . To ensure that such values are correctly stored internally but displayed with only two digits of precision you can insert the string .2 between the symbol and the conversion specifier printf The result is .2f 12 The output from this command is The result is But you actually have even more control than that because you can also specify whether to pad output with either zeros or spaces by prefacing the specifier with certain values. Example 7-1 shows five possible combinations. Example 7-1. Precision setting php echo pre Enables viewing of the spaces Pad to 15 spaces printf The result is 15f n 12 Pad to 15 spaces fill with zeros printf The result is 015f n 12 Pad to 15 spaces 2 decimal places precision printf The result is n 12 Pad to 15 spaces 2 decimal places precision fill with zeros printf The result is n 12 Pad to 15 spaces 2 decimal places precision fill with symbol printf The result is n 12 The output from this example looks like this The result is The result is The result is The result is The result is The way it works is simple if you go from right to left see Table 7-2 . Notice that The rightmost character is the conversion specifier. In this case it is f for floating point. Just before the conversion specifier if there is a period and a number together then the precision of the output is specified as the value of the number. Using printf 131 Regardless of whether there s a precision specifier if there is a number then that represents the amount of characters to which the output should be padded. In the previous example

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.