Java Reference
In-Depth Information
Table 4-12.
(
continued
)
Method
Description
toLocaleUpperCase()
Works the same as the
toUpperCase()
, except that it
uses locale specific lowercase to uppercase character
mapping
toString()
Returns the contents of the String object as a primitive
string value
trim()
Returns a primitive string value by removing the
whitespaces from the string
valueOf()
Same as
toString()
The Number Object
The
Number
object is a function. It can be called as a function or a constructor. When it is
called as a function, it converts the supplied argument to a primitive number value.
If it is called with no argument, it returns the primitive number zero. When it is called
as a constructor, it returns a Number object that wraps the specified argument. You can
think of the Number object as the wrapper objects
Integer
,
Long
,
Float
,
Double
,
Short
,
and
Byte
types in Java. The
valueOf()
method of the Number object returns the primitive
number value stored in the object. The following code shows how to use the Number
object as a function and a constructor:
// Converts the string "24" to a number 24 and assigns 24 to n1
var n1 = Number("24");
// Asigns zero to n2
var n2 = Number();
// Create a Number object for the nuembr 100.43
var n3 = new Number(100.43);
printf("n1 = %d, n2 = %d, n3 = %f", n1, n2, n3.valueOf());
n1 = 24, n2 = 0, n3 = 100.430000
The Number object contains several useful properties to work with numbers.
They are listed in Table
4-13
. All listed methods are defined in
Number.prototype
object.
Search WWH ::
Custom Search