78 Part II: Writing Your Own Java Programs (Web hosting directory)
78 Part II: Writing Your Own Java Programs Digits beyond the decimal point Java has two different types that have digits float, Charles has an extra three cents in his beyond the decimal point: type double and account. By changing to the 32-bit floattype, type float. So what s the difference? When I ve clobbered the accuracy in the amount you declare a variable to be of type double, InAccount variable s hundredths place. you re telling the computer to keep track of 64 That s bad. bits when it stores the variable s values. When Another difficulty with floatvalues is purely you declare a variable to be of type float, the cosmetic. Look again at the literals, 50.22and computer keeps track of only 32 bits. 1000000.00, in Listing 4-2. The Laws of Java You could change Listing 4-2 and declare say that literals like these take up 64 bits each. amountInAccountto be of type float. This means that if you declare amountIn Accountto be of type float, you re going to float amountInAccount; run into trouble. You ll have trouble stuffing Surely, 32 bits are enough to store a small those 64-bit literals into your little 32-bit number like 50.22? Well, they are and they amountInAccount variable. To compenaren t. You could easily store 50.00 with only 32 sate, you can switch from double literals to bits. Heck, you could store 50.00 with only 6 bits. floatliterals by adding an Fto each double The size of the number doesn t matter. It s the literal, but a number with an extra Fat the end accuracy that matters. In a 64-bit double vari-looks funny. able, you re using most of the bits to store stuff float amountInAccount; beyond the decimal point. To store the .22 part amountInAccount = of 50.22, you need more than the measly 32 bits 50.22F; that you get with type float. amountInAccount = amountInAccount + Do you really believe what you just read that 1000000.00F; it takes more than 32 bits to store .22? To help convince you, I made a few changes to the code To experiment with numbers, visit http:// in Listing 4-2. I made amountInAccountbe babbage.cs.qc.edu/courses/cs341/ of type float, and the output I got was IEEE-754.html. The page takes any number that you enter and shows you how the You have $1000050.25 in your number would be represented as 32 bits and as account. 64 bits. Compare this with the output in Figure 4-3. When I switch from type double to type More important than the humongous range of the double keyword s numbers is the fact that a doublevalue can have digits beyond the decimal point. After you declare amountInAccountto be of type double, you can store all sorts of numbers in amountInAccount. You can store 50.22, 0.02398479, or 3.0. In Listing 4-2, if I hadn t declared amountInAccountto be of type double, I may not have been able to store 50.22. Instead, I would have had to store plain old 50, without any digits beyond the decimal point.
Sbc yahoo internet provider is a name that we will not do any shame to. We are as good in what we do. Our sbc yahoo web hosting team will work hard to meet and satisfy all your web hosting needs.Try us out!