TAILIEUCHUNG - Beginning Microsoft Visual Basic 2008 phần 2

hai hoặc ba sẽ là tốt! Những gì bạn cần là để định dạng chuỗi như vậy mà bạn nhìn thấy tất cả mọi thứ ở bên trái của điểm thập phân, nhưng chỉ có ba chữ số ở bên phải, đó là những gì bạn làm trong kế tiếp dùng thử. | Chapter 3 Writing Software Formatting Strings Often when working with numbers you ll need to alter the way they are displayed as a string. Figure 3-5 shows how a division operator works. In this case you don t really need to see 14 decimal places two or three would be fine What you need is to format the string so that you see everything to the left of the decimal point but only three digits to the right which is what you do in the next Try It Out. Try It Out Formatting Strings 1. Open the Floating-Point Math project that you created earlier in this chapter. 2. Open the Code Editor for Forml and make the following changes Set number divide numbers and display results dblNumber 12 dblNumber 7 Display the results without formatting Division test without formatting. _ Floating Points Display the results with formatting Division test with formatting. _ 0 n3 dblNumber Floating Points End Sub 3. Run the project. After the message box dialog box for the multiplication test is displayed you ll see two more message boxes as shown in Figure 3-10. Figure 3-10 How It Works The magic here is in the call to . This powerful method allows the formatting of numbers. The key is all in the first parameter as this defines the format the final string will take Division test with formatting. _ 0 n3 dblNumber Floating Points 59 Chapter 3 Writing Software You passed two parameters. The first parameter 0 n3 is the format that you want. The second parameter dblNumber is the value that you want to format. Note that since you are formatting a number to a string representation you do not need to provide the ToString method after dblNumber as in the previous call to the Show method of the MessageBox class. This is because the method is looking for a number and not a string. The 0 in the format tells to work with the zeroth data parameter which is .

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.