Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |

You use an instance of one of the`Number`

classes—`Byte`

,`Double`

,`Float`

,`Integer`

,`Long`

, and`Short`

—to contain a number of primitive type. You can also use`BigInteger`

and`BigDecimal`

for arbitrary-precision numbers.The

`Number`

classes include class methods and constants, which are useful in a variety of ways. The`MIN_VALUE`

and`MAX_VALUE`

constants contain the smallest and largest values that can be contained by an object of that type. The`byteValue`

,`shortValue`

, and similar methods convert one numeric type to another. The`valueOf`

method converts a string to a number, and the`toString`

method converts a number to a string.To format a number to display to an end user, you use the

`NumberFormat`

class in the`java.text`

package. When using`NumberFormat`

, you can get a default format for decimal numbers, percentages, or currency. Or, you can design a custom format using patterns. If you are using JDK 5.0 or later, the`printf`

facility provides yet another means for formatting your output.The

`Math`

class contains a variety of class methods for performing mathematical functions. This class includes the trigonometric functions, such as computing sine, cosine, and so on.`Math`

also includes functions for logarithm calculations, as well as basic arithmetic functions, such as rounding. Finally,`Math`

contains a method,`random`

, for generating random numbers.

Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |

Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.