This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Hello, I just wanted to know how to restrict the number of floating point digits of a float value. I mean after the decimal point after have only 3 digits. like 20.111(only three 1s). Thank you very much.
SCJP 1.4, SCMAD 1.0<br />SCWCD, SCBCD (in progress)
You might consider not using floats. Use long or int to store the real number * 1000. Format the decimal places only for display. This is one way to make sure the 3-digit fractional part multplies, divides and rounds the way you'd expect. It might be fun to make your own number class that uses float for all input and output but hides ints internally.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi