Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 8b99df826c3b6cf56a1caaae5f931d50 > files > 821

ruby-actionpack-2.3.4-1mdv2010.0.noarch.rpm

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActionView::Helpers::NumberHelper</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActionView::Helpers::NumberHelper</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/lib/action_view/helpers/number_helper_rb.html">
                lib/action_view/helpers/number_helper.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Provides methods for converting numbers into formatted strings. Methods are
provided for phone numbers, currency, percentage, precision, positional
notation, and file size.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000446">number_to_currency</a>&nbsp;&nbsp;
      <a href="#M000450">number_to_human_size</a>&nbsp;&nbsp;
      <a href="#M000447">number_to_percentage</a>&nbsp;&nbsp;
      <a href="#M000445">number_to_phone</a>&nbsp;&nbsp;
      <a href="#M000448">number_with_delimiter</a>&nbsp;&nbsp;
      <a href="#M000449">number_with_precision</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">


    <div id="constants-list">
      <h3 class="section-bar">Constants</h3>

      <div class="name-list">
        <table summary="Constants">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">STORAGE_UNITS</td>
          <td>=</td>
          <td class="context-item-value">[:byte, :kb, :mb, :gb, :tb].freeze</td>
        </tr>
        </table>
      </div>
    </div>



      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000446" class="method-detail">
        <a name="M000446"></a>

        <div class="method-heading">
          <a href="NumberHelper.src/M000446.html" target="Code" class="method-signature"
            onclick="popupCode('NumberHelper.src/M000446.html');return false;">
          <span class="method-name">number_to_currency</span><span class="method-args">(number, options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Formats a <tt>number</tt> into a currency string (e.g., $13.65). You can
customize the format in the <tt>options</tt> hash.
</p>
<h4>Options</h4>
<ul>
<li><tt>:precision</tt> - Sets the level of precision (defaults to 2).

</li>
<li><tt>:unit</tt> - Sets the denomination of the currency (defaults to
&quot;$&quot;).

</li>
<li><tt>:separator</tt> - Sets the separator between the units (defaults to
&quot;.&quot;).

</li>
<li><tt>:delimiter</tt> - Sets the thousands delimiter (defaults to
&quot;,&quot;).

</li>
<li><tt>:format</tt> - Sets the format of the output string (defaults to
&quot;%u%n&quot;). The field types are:

<pre>
  %u  The currency unit
  %n  The number
</pre>
</li>
</ul>
<h4>Examples</h4>
<pre>
 number_to_currency(1234567890.50)                    # =&gt; $1,234,567,890.50
 number_to_currency(1234567890.506)                   # =&gt; $1,234,567,890.51
 number_to_currency(1234567890.506, :precision =&gt; 3)  # =&gt; $1,234,567,890.506

 number_to_currency(1234567890.50, :unit =&gt; &quot;&amp;pound;&quot;, :separator =&gt; &quot;,&quot;, :delimiter =&gt; &quot;&quot;)
 # =&gt; &amp;pound;1234567890,50
 number_to_currency(1234567890.50, :unit =&gt; &quot;&amp;pound;&quot;, :separator =&gt; &quot;,&quot;, :delimiter =&gt; &quot;&quot;, :format =&gt; &quot;%n %u&quot;)
 # =&gt; 1234567890,50 &amp;pound;
</pre>
        </div>
      </div>

      <div id="method-M000450" class="method-detail">
        <a name="M000450"></a>

        <div class="method-heading">
          <a href="NumberHelper.src/M000450.html" target="Code" class="method-signature"
            onclick="popupCode('NumberHelper.src/M000450.html');return false;">
          <span class="method-name">number_to_human_size</span><span class="method-args">(number, *args)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Formats the bytes in <tt>size</tt> into a more understandable
representation (e.g., giving it 1500 yields 1.5 KB). This method is useful
for reporting file sizes to users. This method returns nil if <tt>size</tt>
cannot be converted into a number. You can customize the format in the
<tt>options</tt> hash.
</p>
<h4>Options</h4>
<ul>
<li><tt>:precision</tt> - Sets the level of precision (defaults to 1).

</li>
<li><tt>:separator</tt> - Sets the separator between the units (defaults to
&quot;.&quot;).

</li>
<li><tt>:delimiter</tt> - Sets the thousands delimiter (defaults to
&quot;&quot;).

</li>
</ul>
<h4>Examples</h4>
<pre>
 number_to_human_size(123)                                          # =&gt; 123 Bytes
 number_to_human_size(1234)                                         # =&gt; 1.2 KB
 number_to_human_size(12345)                                        # =&gt; 12.1 KB
 number_to_human_size(1234567)                                      # =&gt; 1.2 MB
 number_to_human_size(1234567890)                                   # =&gt; 1.1 GB
 number_to_human_size(1234567890123)                                # =&gt; 1.1 TB
 number_to_human_size(1234567, :precision =&gt; 2)                     # =&gt; 1.18 MB
 number_to_human_size(483989, :precision =&gt; 0)                      # =&gt; 473 KB
 number_to_human_size(1234567, :precision =&gt; 2, :separator =&gt; ',')  # =&gt; 1,18 MB
</pre>
<p>
You can still use <tt><a
href="NumberHelper.html#M000450">number_to_human_size</a></tt> with the old
API that accepts the <tt>precision</tt> as its optional second parameter:
</p>
<pre>
 number_to_human_size(1234567, 2)    # =&gt; 1.18 MB
 number_to_human_size(483989, 0)     # =&gt; 473 KB
</pre>
        </div>
      </div>

      <div id="method-M000447" class="method-detail">
        <a name="M000447"></a>

        <div class="method-heading">
          <a href="NumberHelper.src/M000447.html" target="Code" class="method-signature"
            onclick="popupCode('NumberHelper.src/M000447.html');return false;">
          <span class="method-name">number_to_percentage</span><span class="method-args">(number, options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Formats a <tt>number</tt> as a percentage string (e.g., 65%). You can
customize the format in the <tt>options</tt> hash.
</p>
<h4>Options</h4>
<ul>
<li><tt>:precision</tt> - Sets the level of precision (defaults to 3).

</li>
<li><tt>:separator</tt> - Sets the separator between the units (defaults to
&quot;.&quot;).

</li>
<li><tt>:delimiter</tt> - Sets the thousands delimiter (defaults to
&quot;&quot;).

</li>
</ul>
<h4>Examples</h4>
<pre>
 number_to_percentage(100)                                        # =&gt; 100.000%
 number_to_percentage(100, :precision =&gt; 0)                       # =&gt; 100%
 number_to_percentage(1000, :delimiter =&gt; '.', :separator =&gt; ',') # =&gt; 1.000,000%
 number_to_percentage(302.24398923423, :precision =&gt; 5)           # =&gt; 302.24399%
</pre>
        </div>
      </div>

      <div id="method-M000445" class="method-detail">
        <a name="M000445"></a>

        <div class="method-heading">
          <a href="NumberHelper.src/M000445.html" target="Code" class="method-signature"
            onclick="popupCode('NumberHelper.src/M000445.html');return false;">
          <span class="method-name">number_to_phone</span><span class="method-args">(number, options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Formats a <tt>number</tt> into a US phone number (e.g., (555) 123-9876).
You can customize the format in the <tt>options</tt> hash.
</p>
<h4>Options</h4>
<ul>
<li><tt>:area_code</tt> - Adds parentheses around the area code.

</li>
<li><tt>:delimiter</tt> - Specifies the delimiter to use (defaults to
&quot;-&quot;).

</li>
<li><tt>:extension</tt> - Specifies an extension to add to the end of the
generated number.

</li>
<li><tt>:country_code</tt> - Sets the country code for the phone number.

</li>
</ul>
<h4>Examples</h4>
<pre>
 number_to_phone(5551234)                                           # =&gt; 555-1234
 number_to_phone(1235551234)                                        # =&gt; 123-555-1234
 number_to_phone(1235551234, :area_code =&gt; true)                    # =&gt; (123) 555-1234
 number_to_phone(1235551234, :delimiter =&gt; &quot; &quot;)                     # =&gt; 123 555 1234
 number_to_phone(1235551234, :area_code =&gt; true, :extension =&gt; 555) # =&gt; (123) 555-1234 x 555
 number_to_phone(1235551234, :country_code =&gt; 1)                    # =&gt; +1-123-555-1234

 number_to_phone(1235551234, :country_code =&gt; 1, :extension =&gt; 1343, :delimiter =&gt; &quot;.&quot;)
 =&gt; +1.123.555.1234 x 1343
</pre>
        </div>
      </div>

      <div id="method-M000448" class="method-detail">
        <a name="M000448"></a>

        <div class="method-heading">
          <a href="NumberHelper.src/M000448.html" target="Code" class="method-signature"
            onclick="popupCode('NumberHelper.src/M000448.html');return false;">
          <span class="method-name">number_with_delimiter</span><span class="method-args">(number, *args)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Formats a <tt>number</tt> with grouped thousands using <tt>delimiter</tt>
(e.g., 12,324). You can customize the format in the <tt>options</tt> hash.
</p>
<h4>Options</h4>
<ul>
<li><tt>:delimiter</tt> - Sets the thousands delimiter (defaults to
&quot;,&quot;).

</li>
<li><tt>:separator</tt> - Sets the separator between the units (defaults to
&quot;.&quot;).

</li>
</ul>
<h4>Examples</h4>
<pre>
 number_with_delimiter(12345678)                        # =&gt; 12,345,678
 number_with_delimiter(12345678.05)                     # =&gt; 12,345,678.05
 number_with_delimiter(12345678, :delimiter =&gt; &quot;.&quot;)     # =&gt; 12.345.678
 number_with_delimiter(12345678, :separator =&gt; &quot;,&quot;)     # =&gt; 12,345,678
 number_with_delimiter(98765432.98, :delimiter =&gt; &quot; &quot;, :separator =&gt; &quot;,&quot;)
 # =&gt; 98 765 432,98
</pre>
<p>
You can still use <tt><a
href="NumberHelper.html#M000448">number_with_delimiter</a></tt> with the
old API that accepts the <tt>delimiter</tt> as its optional second and the
<tt>separator</tt> as its optional third parameter:
</p>
<pre>
 number_with_delimiter(12345678, &quot; &quot;)                     # =&gt; 12 345.678
 number_with_delimiter(12345678.05, &quot;.&quot;, &quot;,&quot;)             # =&gt; 12.345.678,05
</pre>
        </div>
      </div>

      <div id="method-M000449" class="method-detail">
        <a name="M000449"></a>

        <div class="method-heading">
          <a href="NumberHelper.src/M000449.html" target="Code" class="method-signature"
            onclick="popupCode('NumberHelper.src/M000449.html');return false;">
          <span class="method-name">number_with_precision</span><span class="method-args">(number, *args)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Formats a <tt>number</tt> with the specified level of <tt>:precision</tt>
(e.g., 112.32 has a precision of 2). You can customize the format in the
<tt>options</tt> hash.
</p>
<h4>Options</h4>
<ul>
<li><tt>:precision</tt> - Sets the level of precision (defaults to 3).

</li>
<li><tt>:separator</tt> - Sets the separator between the units (defaults to
&quot;.&quot;).

</li>
<li><tt>:delimiter</tt> - Sets the thousands delimiter (defaults to
&quot;&quot;).

</li>
</ul>
<h4>Examples</h4>
<pre>
 number_with_precision(111.2345)                    # =&gt; 111.235
 number_with_precision(111.2345, :precision =&gt; 2)   # =&gt; 111.23
 number_with_precision(13, :precision =&gt; 5)         # =&gt; 13.00000
 number_with_precision(389.32314, :precision =&gt; 0)  # =&gt; 389
 number_with_precision(1111.2345, :precision =&gt; 2, :separator =&gt; ',', :delimiter =&gt; '.')
 # =&gt; 1.111,23
</pre>
<p>
You can still use <tt><a
href="NumberHelper.html#M000449">number_with_precision</a></tt> with the
old API that accepts the <tt>precision</tt> as its optional second
parameter:
</p>
<pre>
  number_with_precision(number_with_precision(111.2345, 2)   # =&gt; 111.23
</pre>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>