<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>Prototype JavaScript framework - Number</title>
  <id>tag:www.prototypejs.org,2008:mephisto/api/number</id>
  <generator uri="http://mephistoblog.com" version="0.7.3">Mephisto Noh-Varr</generator>
  <link href="http://www.prototypejs.org/feed/api/number/atom.xml" rel="self" type="application/atom+xml"/>
  <link href="http://www.prototypejs.org/api/number" rel="alternate" type="text/html"/>
  <updated>2007-11-06T03:09:27Z</updated>
  <entry xml:base="http://www.prototypejs.org/">
    <author>
      <name>Andrew</name>
    </author>
    <id>tag:www.prototypejs.org,2007-11-06:17772</id>
    <published>2007-11-06T03:08:00Z</published>
    <updated>2007-11-06T03:09:27Z</updated>
    <category term="Number"/>
    <category term="1.6.0"/>
    <link href="http://www.prototypejs.org/api/number/round" rel="alternate" type="text/html"/>
    <title>round</title>
<summary type="html">&lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;round() -&gt; Number&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Rounds the number to the nearest integer.&lt;/p&gt;</summary><content type="html">
            &lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;round() -&gt; Number&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Rounds the number to the nearest integer.&lt;/p&gt;
&lt;p&gt;An instance-method version of &lt;a href=&quot;http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Math:round&quot;&gt;&lt;code&gt;Math.round&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;Examples&lt;/h3&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;Math.round(4.5) //-&gt; 5
(4.5).round()   //-&gt; 5
(4.49).round()  //-&gt; 4
(-4.5).round()  //-&gt; -4&lt;/code&gt;&lt;/pre&gt;
          </content>  </entry>
  <entry xml:base="http://www.prototypejs.org/">
    <author>
      <name>Andrew</name>
    </author>
    <id>tag:www.prototypejs.org,2007-11-06:17771</id>
    <published>2007-11-06T03:06:00Z</published>
    <updated>2007-11-06T03:06:48Z</updated>
    <category term="Number"/>
    <category term="1.6.0"/>
    <link href="http://www.prototypejs.org/api/number/floor" rel="alternate" type="text/html"/>
    <title>floor</title>
<summary type="html">&lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;floor() -&gt; Number&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Returns the largest integer less than or equal to the number.&lt;/p&gt;</summary><content type="html">
            &lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;floor() -&gt; Number&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Returns the largest integer less than or equal to the number.&lt;/p&gt;
&lt;p&gt;An instance-method version of &lt;a href=&quot;http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Math:floor&quot;&gt;&lt;code&gt;Math.floor&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;Examples&lt;/h3&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;Math.floor(4.6) //-&gt; 4
(4.6).floor()   //-&gt; 4
(-4.1).floor()  //-&gt; -5&lt;/code&gt;&lt;/pre&gt;
          </content>  </entry>
  <entry xml:base="http://www.prototypejs.org/">
    <author>
      <name>Andrew</name>
    </author>
    <id>tag:www.prototypejs.org,2007-11-06:17770</id>
    <published>2007-11-06T03:03:00Z</published>
    <updated>2007-11-06T03:06:17Z</updated>
    <category term="Number"/>
    <category term="1.6.0"/>
    <link href="http://www.prototypejs.org/api/number/ceil" rel="alternate" type="text/html"/>
    <title>ceil</title>
<summary type="html">&lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;ceil() -&gt; Number&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Returns the smallest integer greater than or equal to the number.&lt;/p&gt;</summary><content type="html">
            &lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;ceil() -&gt; Number&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Returns the smallest integer greater than or equal to the number.&lt;/p&gt;
&lt;p&gt;An instance-method version of &lt;a href=&quot;http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Math:ceil&quot;&gt;&lt;code&gt;Math.ceil&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;Examples&lt;/h3&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;Math.ceil(4.1) //-&gt; 5
(4.1).ceil()   //-&gt; 5
(-4.1).ceil()  //-&gt; -4&lt;/code&gt;&lt;/pre&gt;
          </content>  </entry>
  <entry xml:base="http://www.prototypejs.org/">
    <author>
      <name>Andrew</name>
    </author>
    <id>tag:www.prototypejs.org,2007-11-06:17768</id>
    <published>2007-11-06T02:58:00Z</published>
    <updated>2007-11-06T03:01:09Z</updated>
    <category term="Number"/>
    <category term="1.6.0"/>
    <link href="http://www.prototypejs.org/api/number/abs" rel="alternate" type="text/html"/>
    <title>abs</title>
<summary type="html">&lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;abs() -&gt; Number&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Returns the absolute value of the number.&lt;/p&gt;</summary><content type="html">
            &lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;abs() -&gt; Number&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Returns the absolute value of the number.&lt;/p&gt;
&lt;p&gt;An instance-method version of &lt;a href=&quot;http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Math:abs&quot;&gt;&lt;code&gt;Math.abs&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;Examples&lt;/h3&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;Math.abs(-5) //-&gt; 5
(-5).abs()   //-&gt; 5
(5).abs()    //-&gt; 5&lt;/code&gt;&lt;/pre&gt;
          </content>  </entry>
  <entry xml:base="http://www.prototypejs.org/">
    <author>
      <name>Tobie</name>
    </author>
    <id>tag:www.prototypejs.org,2007-03-10:14771</id>
    <published>2007-03-10T00:44:00Z</published>
    <updated>2007-03-10T00:54:24Z</updated>
    <category term="Number"/>
    <category term="1.5.1"/>
    <link href="http://www.prototypejs.org/api/number/tojson" rel="alternate" type="text/html"/>
    <title>toJSON</title>
<summary type="html">&lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;toJSON() -&gt; String&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Returns a JSON string.&lt;/p&gt;</summary><content type="html">
            &lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;toJSON() -&gt; String&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Returns a JSON string.&lt;/p&gt;
&lt;h3&gt;Example&lt;/h3&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
(45).toJSON();
//-&gt; '45'
&lt;/code&gt;&lt;/pre&gt;
          </content>  </entry>
  <entry xml:base="http://www.prototypejs.org/">
    <author>
      <name>Tobie</name>
    </author>
    <id>tag:www.prototypejs.org,2007-03-09:14757</id>
    <published>2007-03-09T19:03:00Z</published>
    <updated>2007-03-09T19:38:19Z</updated>
    <category term="Number"/>
    <category term="1.5.1"/>
    <link href="http://www.prototypejs.org/api/number/toPaddedString" rel="alternate" type="text/html"/>
    <title>toPaddedString</title>
<summary type="html">&lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;toPaddedString(length[, radix]) -&gt; String&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Converts the number into a string padded with &lt;code&gt;0&lt;/code&gt;s so that the string&#8217;s length is at least equal to &lt;code&gt;length&lt;/code&gt;. Takes an optional &lt;code&gt;radix&lt;/code&gt; argument which specifies the base to use for conversion.&lt;/p&gt;</summary><content type="html">
            &lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;toPaddedString(length[, radix]) -&gt; String&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Converts the number into a string padded with &lt;code&gt;0&lt;/code&gt;s so that the string&#8217;s length is at least equal to &lt;code&gt;length&lt;/code&gt;. Takes an optional &lt;code&gt;radix&lt;/code&gt; argument which specifies the base to use for conversion.&lt;/p&gt;
&lt;h3&gt;Examples&lt;/h3&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
(13).toPaddedString(4);
// -&gt; '0013'

(13).toPaddedString(2);
// -&gt; '13'

(13).toPaddedString(1);
// -&gt; '13'

(13).toPaddedString(4, 16)
// -&gt; '000d'

(13).toPaddedString(4, 2);
// -&gt; '1101'
&lt;/code&gt;&lt;/pre&gt;
          </content>  </entry>
  <entry xml:base="http://www.prototypejs.org/">
    <author>
      <name>Justin</name>
    </author>
    <id>tag:www.prototypejs.org,2006-12-05:12751</id>
    <published>2006-12-05T21:47:00Z</published>
    <updated>2007-03-20T12:41:47Z</updated>
    <category term="Number"/>
    <link href="http://www.prototypejs.org/api/number" rel="alternate" type="text/html"/>
    <title>Number</title>
<content type="html">
            &lt;p&gt;Prototype extends native JavaScript numbers in order to provide:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;/api/objectRange&quot;&gt;&lt;code&gt;ObjectRange&lt;/code&gt;&lt;/a&gt; compatibility, through &lt;a href=&quot;/api/number/succ&quot;&gt;&lt;code&gt;Number#succ&lt;/code&gt;&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Ruby-like numerical loops with &lt;a href=&quot;/api/number/times&quot;&gt;&lt;code&gt;Number#times&lt;/code&gt;&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Simple utility methods such as &lt;a href=&quot;/api/number/toColorPart&quot;&gt;&lt;code&gt;Number#toColorPart&lt;/code&gt;&lt;/a&gt; and &lt;a href=&quot;/api/number/toPaddedString&quot;&gt;&lt;code&gt;Number#toPaddedString&lt;/code&gt;&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;What becomes possible&lt;/h3&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
$R(1, 10).each(function(index) {
  // This gets invoked with index from 1 to 10, inclusive
});

(5).times(function(n) {
  // This gets invoked with index from 0 to 5, *exclusive*
  // The parentheses are due to JS syntax, if we did not use a literal, they'd be superfluous
});

(128).toColorPart()
// -&gt; '80'

(10).toColorPart()
// -&gt; '0a'

'#' + [128, 10, 16].invoke('toColorPart').join('')
// -&gt; '#800a10'
&lt;/code&gt;&lt;/pre&gt;
          </content>  </entry>
  <entry xml:base="http://www.prototypejs.org/">
    <author>
      <name>Andrew</name>
    </author>
    <id>tag:www.prototypejs.org,2006-11-18:12491</id>
    <published>2006-11-18T18:00:00Z</published>
    <updated>2007-01-06T16:03:53Z</updated>
    <category term="Number"/>
    <link href="http://www.prototypejs.org/api/number/succ" rel="alternate" type="text/html"/>
    <title>succ</title>
<summary type="html">&lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;succ() -&gt; Number&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Returns the successor of the current &lt;code&gt;Number&lt;/code&gt;, as defined by current + 1.  Used to make numbers compatible with &lt;a href=&quot;/api/objectRange&quot;&gt;&lt;code&gt;ObjectRange&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;</summary><content type="html">
            &lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;succ() -&gt; Number&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Returns the successor of the current &lt;code&gt;Number&lt;/code&gt;, as defined by current + 1.  Used to make numbers compatible with &lt;a href=&quot;/api/objectRange&quot;&gt;&lt;code&gt;ObjectRange&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;Examples&lt;/h3&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
(5).succ()
// -&gt; 6

$A($R(1, 5)).join('')
// -&gt; '12345'
&lt;/code&gt;&lt;/pre&gt;
          </content>  </entry>
  <entry xml:base="http://www.prototypejs.org/">
    <author>
      <name>Andrew</name>
    </author>
    <id>tag:www.prototypejs.org,2006-11-18:12492</id>
    <published>2006-11-18T18:00:00Z</published>
    <updated>2007-01-06T16:05:08Z</updated>
    <category term="Number"/>
    <link href="http://www.prototypejs.org/api/number/times" rel="alternate" type="text/html"/>
    <title>times</title>
<summary type="html">&lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;times(iterator) -&gt; Number&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Encapsulates a regular [0..n[ loop, Ruby-style.&lt;/p&gt;</summary><content type="html">
            &lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;times(iterator) -&gt; Number&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Encapsulates a regular [0..n[ loop, Ruby-style.&lt;/p&gt;
&lt;p&gt;The callback function is invoked with a single argument, ranging from 0 to the number, &lt;strong&gt;exclusive&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;Examples&lt;/h3&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
var s = '';
(5).times(function(n) {
  s += n;
});

s
// -&gt; '01234'
&lt;/code&gt;&lt;/pre&gt;
          </content>  </entry>
  <entry xml:base="http://www.prototypejs.org/">
    <author>
      <name>Andrew</name>
    </author>
    <id>tag:www.prototypejs.org,2006-11-18:12490</id>
    <published>2006-11-18T17:59:00Z</published>
    <updated>2007-01-06T16:06:23Z</updated>
    <category term="Number"/>
    <link href="http://www.prototypejs.org/api/number/toColorPart" rel="alternate" type="text/html"/>
    <title>toColorPart</title>
<summary type="html">&lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;toColorPart() -&gt; String&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Produces a 2-digit hexadecimal representation of the number (which is therefore assumed to be in the [0..255] range).  Useful for composing CSS color strings.&lt;/p&gt;</summary><content type="html">
            &lt;pre&gt;&lt;code class=&quot;ebnf&quot;&gt;toColorPart() -&gt; String&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Produces a 2-digit hexadecimal representation of the number (which is therefore assumed to be in the [0..255] range).  Useful for composing CSS color strings.&lt;/p&gt;
&lt;h3&gt;Examples&lt;/h3&gt;

&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;
128.toColorPart()
// -&gt; '70'

10.toColorPart()
// -&gt; '0a'

'#' + [128, 10, 16].invoke('toColorPart').join('')
// -&gt; '#800a10'
&lt;/code&gt;&lt;/pre&gt;
          </content>  </entry>
</feed>
