Eight Weeks of Prototype: Week 3, Prototype Data Types
The Number Data Type
For the most part, these methods are just wrappers to the normal
Math object methods. For example, the abs() method corresponds to the
Math.abs() method. Similarly, the ceil(), floor() and round() methods also correspond to the respective
Aside from these methods, the only other methods of any great use are the
toColorPart() method is used to convert a number (assumed to be in the range of
255) to a 2 character hexadecimal number. This allows you to easily create a CSS colour string.
Listing 3 shows how
toColorPart can be used. Later in this article we'll look at another way of using this method by making use of the array methods Prototype provides.
toPaddedString() method is useful for created a zero-padded string based on the target number. For example, calling
(25).toPaddString(5) will result in a string 5 characters in length. That is,