Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
You use an instance of one of theNumber
classes-Byte
,Double
,Float
,Integer
,Long
, andShort
-to contain a number of primitive type. You can also useBigInteger
andBigDecimal
for arbitrary-precision numbers.The
Number
classes include class methods and constants, which are useful in a variety of ways. TheMIN_VALUE
andMAX_VALUE
constants contain the smallest and largest values that can be contained by an object of that type. ThebyteValue
,shortValue
, and similar methods convert one numeric type to another. ThevalueOf
method converts a string to a number, and thetoString
method converts a number to a string.To format a number to display to an end user, you use the
NumberFormat
class in thejava.text
package. When usingNumberFormat
, you can get a default format for decimal numbers, percentages, or currency. Or, you can design a custom format using patterns.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-2004 Sun Microsystems, Inc. All rights reserved.