You use one of the wrapper classes –Byte,Double,Float,Integer,Long, orShort– to wrap a number of primitive type in an object. The Java compiler automatically wraps (boxes) primitives for you when necessary and unboxes them, again when necessary.The
Numberclasses include constants and useful class methods. TheMIN_VALUEandMAX_VALUEconstants 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. ThevalueOfmethod converts a string to a number, and thetoStringmethod converts a number to a string.To format a string containing numbers for output, you can use the
printf()orformat()methods in thePrintStreamclass. Alternatively, you can use theNumberFormatclass to customize numerical formats using patterns.The
Mathclass contains a variety of class methods for performing mathematical functions, including exponential, logarithmic, and trigonometric methods.Mathalso includes basic arithmetic functions, such as absolute value and rounding, and a method,random(), for generating random numbers.
ATENCIÓN: La traducción de esta documentación es un esfuerzo personal y voluntario. NO es un documento oficial del propietario de la tecnología Java, Oracle, ni está patrocinado por esta empresa.
Los documentos originales y actualizados (en inglés) están disponibles en: http://docs.oracle.com/javase/tutorial/. La versión disponible en este sitio es la publicada en Marzo de 2008 (más información en: "What's new and What's Old? The History of the Tutorial").
Dirige cualquier comentario, petición, felicitación, etc. a tutorialesjava@codexion.com.
Si quieres ayudar a mantener en funcionamiento esta web, colaborar con la traducción de estos documentos o necesitas que se traduzca algún capítulo en concreto puedes invitarme a un café: