<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.numberformatter.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'numberformatter.setattribute.php',
    1 => 'NumberFormatter::setAttribute',
    2 => 'Set an attribute',
  ),
  'up' => 
  array (
    0 => 'class.numberformatter.php',
    1 => 'NumberFormatter',
  ),
  'prev' => 
  array (
    0 => 'numberformatter.parsecurrency.php',
    1 => 'NumberFormatter::parseCurrency',
  ),
  'next' => 
  array (
    0 => 'numberformatter.setpattern.php',
    1 => 'NumberFormatter::setPattern',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/intl/numberformatter/set-attribute.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="numberformatter.setattribute" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">NumberFormatter::setAttribute</h1>
  <h1 class="refname">numfmt_set_attribute</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8, PECL intl &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">NumberFormatter::setAttribute</span> -- <span class="refname">numfmt_set_attribute</span> &mdash; <span class="dc-title">Set an attribute</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-numberformatter.setattribute-description">
  <h3 class="title">Descrizione</h3>
  <p class="para">
   Stile orientato agli oggetti
  </p>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>NumberFormatter::setAttribute</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$attribute</code></span>, <span class="methodparam"><span class="type"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span>|<span class="type"><a href="language.types.float.php" class="type float">float</a></span></span> <code class="parameter">$value</code></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   Stile procedurale
  </p>
  <div class="methodsynopsis dc-description"><span class="methodname"><strong>numfmt_set_attribute</strong></span>(<span class="methodparam"><span class="type"><a href="class.numberformatter.php" class="type NumberFormatter">NumberFormatter</a></span> <code class="parameter">$formatter</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$attribute</code></span>, <span class="methodparam"><span class="type"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span>|<span class="type"><a href="language.types.float.php" class="type float">float</a></span></span> <code class="parameter">$value</code></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   Set a numeric attribute associated with the formatter. An example of a
   numeric attribute is the number of integer digits the formatter will
   produce.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-numberformatter.setattribute-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">formatter</code></dt>
     <dd>
      <p class="para">
       <span class="classname"><a href="class.numberformatter.php" class="classname">NumberFormatter</a></span> object.
      </p>
     </dd>
    
    
     <dt><code class="parameter">attribute</code></dt>
     <dd>
      <p class="para">
       Attribute specifier - one of the
       <a href="class.numberformatter.php#intl.numberformatter-constants.unumberformatattribute" class="link">
        numeric attribute</a> constants.
      </p>
     </dd>
    
    
     <dt><code class="parameter">value</code></dt>
     <dd>
      <p class="para">
       The attribute value.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>



 <div class="refsect1 returnvalues" id="refsect1-numberformatter.setattribute-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="para">
   Restituisce <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> in caso di successo, <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> in caso di fallimento.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-numberformatter.setattribute-examples">
  <h3 class="title">Esempi</h3>
  <div class="example" id="example-1">
   <p><strong>Example #1 <span class="function"><strong>numfmt_set_attribute()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$fmt </span><span style="color: #007700">= </span><span style="color: #0000BB">numfmt_create</span><span style="color: #007700">( </span><span style="color: #DD0000">'de_DE'</span><span style="color: #007700">, </span><span style="color: #0000BB">NumberFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">DECIMAL </span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">"Digits: "</span><span style="color: #007700">.</span><span style="color: #0000BB">numfmt_get_attribute</span><span style="color: #007700">(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">, </span><span style="color: #0000BB">NumberFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">MAX_FRACTION_DIGITS</span><span style="color: #007700">).</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">numfmt_format</span><span style="color: #007700">(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">, </span><span style="color: #0000BB">1234567.891234567890000</span><span style="color: #007700">).</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">numfmt_set_attribute</span><span style="color: #007700">(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">, </span><span style="color: #0000BB">NumberFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">MAX_FRACTION_DIGITS</span><span style="color: #007700">, </span><span style="color: #0000BB">2</span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">"Digits: "</span><span style="color: #007700">.</span><span style="color: #0000BB">numfmt_get_attribute</span><span style="color: #007700">(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">, </span><span style="color: #0000BB">NumberFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">MAX_FRACTION_DIGITS</span><span style="color: #007700">).</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">numfmt_format</span><span style="color: #007700">(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">, </span><span style="color: #0000BB">1234567.891234567890000</span><span style="color: #007700">).</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>
  <div class="example" id="example-2">
   <p><strong>Example #2 OO example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$fmt </span><span style="color: #007700">= new </span><span style="color: #0000BB">NumberFormatter</span><span style="color: #007700">( </span><span style="color: #DD0000">'de_DE'</span><span style="color: #007700">, </span><span style="color: #0000BB">NumberFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">DECIMAL </span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">"Digits: "</span><span style="color: #007700">.</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getAttribute</span><span style="color: #007700">(</span><span style="color: #0000BB">NumberFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">MAX_FRACTION_DIGITS</span><span style="color: #007700">).</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #0000BB">1234567.891234567890000</span><span style="color: #007700">).</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setAttribute</span><span style="color: #007700">(</span><span style="color: #0000BB">NumberFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">MAX_FRACTION_DIGITS</span><span style="color: #007700">, </span><span style="color: #0000BB">2</span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">"Digits: "</span><span style="color: #007700">.</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getAttribute</span><span style="color: #007700">(</span><span style="color: #0000BB">NumberFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">MAX_FRACTION_DIGITS</span><span style="color: #007700">).</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #0000BB">1234567.891234567890000</span><span style="color: #007700">).</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>
  <p class="para">Il precedente esempio visualizzerà:</p>
  <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Digits: 3
1.234.567,891
Digits: 2
1.234.567,89</pre>
</div>
  </div>
  <div class="example" id="example-3">
   <p><strong>Example #3 Using <strong><code><a href="class.numberformatter.php#numberformatter.constants.rounding-mode">NumberFormatter::ROUNDING_MODE</a></code></strong> to truncate values</strong></p>
   <div class="example-contents"><p>
    By default, <span class="classname"><a href="class.numberformatter.php" class="classname">NumberFormatter</a></span> rounds values. Using
    <strong><code><a href="class.numberformatter.php#numberformatter.constants.round-down">NumberFormatter::ROUND_DOWN</a></code></strong> as the
    <strong><code><a href="class.numberformatter.php#numberformatter.constants.rounding-mode">NumberFormatter::ROUNDING_MODE</a></code></strong> truncates
    the value to the specified number of fraction digits without rounding.
   </p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$fmt </span><span style="color: #007700">= new </span><span style="color: #0000BB">NumberFormatter</span><span style="color: #007700">(</span><span style="color: #DD0000">'en_US'</span><span style="color: #007700">, </span><span style="color: #0000BB">NumberFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">DECIMAL</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setAttribute</span><span style="color: #007700">(</span><span style="color: #0000BB">NumberFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">FRACTION_DIGITS</span><span style="color: #007700">, </span><span style="color: #0000BB">2</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #DD0000">"Default rounding mode:\n"</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #0000BB">3.789</span><span style="color: #007700">), </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">; </span><span style="color: #FF8000">// 3.79 (rounded up)<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #0000BB">3.781</span><span style="color: #007700">), </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">; </span><span style="color: #FF8000">// 3.78 (rounded down)<br /><br /></span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setAttribute</span><span style="color: #007700">(</span><span style="color: #0000BB">NumberFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">ROUNDING_MODE</span><span style="color: #007700">, </span><span style="color: #0000BB">NumberFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">ROUND_DOWN</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #DD0000">"\nWith ROUND_DOWN (truncate):\n"</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #0000BB">3.789</span><span style="color: #007700">), </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">; </span><span style="color: #FF8000">// 3.78 (truncated)<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #0000BB">3.781</span><span style="color: #007700">), </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">; </span><span style="color: #FF8000">// 3.78 (truncated)<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>Il precedente esempio visualizzerà:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Default rounding mode:
3.79
3.78

With ROUND_DOWN (truncate):
3.78
3.78</pre>
</div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-numberformatter.setattribute-seealso">
  <h3 class="title">Vedere anche:</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="numberformatter.geterrorcode.php" class="function" rel="rdfs-seeAlso">numfmt_get_error_code()</a> - Get formatter's last error code</span></li>
    <li><span class="function"><a href="numberformatter.getattribute.php" class="function" rel="rdfs-seeAlso">numfmt_get_attribute()</a> - Get an attribute</span></li>
    <li><span class="function"><a href="numberformatter.settextattribute.php" class="function" rel="rdfs-seeAlso">numfmt_set_text_attribute()</a> - Set a text attribute</span></li>
   </ul>
  </p>
 </div>

</div><?php manual_footer($setup); ?>