<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Hi,</p>
    <p>format() is a  class method, not an instance method. However, the
      following does not work either:</p>
    <p>--> String.format("%6.2f", -3.1415926)</p>
    <p>Undefined operation for the given operands.<br>
      check or define function %eo_e for overloading.<br>
    </p>
    <div class="moz-cite-prefix"><br>
    </div>
    <div class="moz-cite-prefix">S.<br>
    </div>
    <div class="moz-cite-prefix">Le 04/05/2021 à 15:44, Samuel Gougeon a
      écrit :<br>
    </div>
    <blockquote type="cite"
      cite="mid:f33e0450-56b8-febd-5460-3c2c69972c20@free.fr">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <p>Dear all,</p>
      <p>May be the question is only about Java, or may be about how
        Scilab implements it.</p>
      <p>In order to do some tests to fix the regression brought by
        Scilab 6 and reported as the major <a moz-do-not-send="true"
href="https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/bugzilla.scilab.org/16376">bug
          16376</a> about how datatips display (big or) small values
        (all displayed as 0 instead of using an exponential notation), i
        am trying to use the <a
href="https://antispam.utc.fr/proxy/2/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/docs.oracle.com/javase/7/docs/api/java/lang/String.html"
          moz-do-not-send="true">java.lang.String</a> class and its <a
          moz-do-not-send="true"
href="https://antispam.utc.fr/proxy/2/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/docs.oracle.com/javase/7/docs/api/java/lang/String.html#format(java.lang.String,%20java.lang.Object...)">.format()
          method</a>, in Scilab language.<br>
      </p>
      <p>Indeed, the java.text.DecimalFormat class used for datatips has
        no <i>self-adaptative format similar to the "%g" printf one</i>
        (that automatically chooses the normal or exponential numerical
        notation according to the magnitude of the absolute value to
        display), while the String class provides this .format() method,
        with <a moz-do-not-send="true"
href="https://antispam.utc.fr/proxy/2/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/docs.oracle.com/javase/7/docs/api/java/util/Formatter.html#syntax">all
          printf formatting conventions</a>, including the "%g" one.<br>
        <br>
        Now, even about only the Java side, something is unclear to me:<br>
        The official documentation of the String class presents
        .format() as a String method, not as a String constructor. <br>
        If so, then .format should be applied to a predefined String.
        But which one? What is done with it? It could be the String
        format, but this one is provided as an explicit input of the
        method...<br>
        <br>
        <font face="monospace">--> jimport java.lang.String<br>
          --> s = String.new()<br>
           s  = <br>
          <br>
          --> s.length()   // OK, this works<br>
           ans  =<br>
            0<br>
          <br>
          --> s.format("%6.2f", -3.1415926)<br>
          Undefined operation for the given operands.<br>
          check or define function %eo_e for overloading.</font></p>
      <p><font face="monospace">--> s = String.new("%6.1f")<br>
           s  = <br>
          %6.1f<br>
        </font></p>
      <p><font face="monospace">--> s.format(-3.1415926)<br>
          Undefined operation for the given operands.<br>
          check or define function %eo_e for overloading.<br>
        </font></p>
      <p>Yet, the .format method is actually listed among all String's
        methods:<br>
        <font face="monospace">--> or(jgetmethods(String)=="format")<br>
           ans  =<br>
            T</font><br>
      </p>
      <p>Using the java.text.DecimalFormat class to fix the bug will
        anyway be possible, with explicit conditions on the magnitude of
        the value to display. But i would like to understand this error
        about String.format().<br>
        <br>
        Any hint is welcome.<br>
      </p>
      <p>Regards<br>
        Samuel<br>
        <br>
      </p>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:users@lists.scilab.org">users@lists.scilab.org</a>
<a class="moz-txt-link-freetext" href="https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users">https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users</a>
</pre>
    </blockquote>
    <pre class="moz-signature" cols="72">-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
<a class="moz-txt-link-freetext" href="http://www.utc.fr/~mottelet">http://www.utc.fr/~mottelet</a>
</pre>
  </body>
</html>