[Scilab-users] Java String.format(format, value) within Scilab

Stéphane Mottelet stephane.mottelet at utc.fr
Tue May 4 16:13:55 CEST 2021


Hi,

format() is a  class method, not an instance method. However, the 
following does not work either:

--> String.format("%6.2f", -3.1415926)

Undefined operation for the given operands.
check or define function %eo_e for overloading.


S.
Le 04/05/2021 à 15:44, Samuel Gougeon a écrit :
>
> Dear all,
>
> May be the question is only about Java, or may be about how Scilab 
> implements it.
>
> In order to do some tests to fix the regression brought by Scilab 6 
> and reported as the major bug 16376 
> <https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/bugzilla.scilab.org/16376> 
> about how datatips display (big or) small values (all displayed as 0 
> instead of using an exponential notation), i am trying to use the 
> java.lang.String 
> <https://antispam.utc.fr/proxy/2/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/docs.oracle.com/javase/7/docs/api/java/lang/String.html> 
> class and its .format() method 
> <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...)>, 
> in Scilab language.
>
> Indeed, the java.text.DecimalFormat class used for datatips has no 
> /self-adaptative format similar to the "%g" printf one/ (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 all printf 
> formatting conventions 
> <https://antispam.utc.fr/proxy/2/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/docs.oracle.com/javase/7/docs/api/java/util/Formatter.html#syntax>, 
> including the "%g" one.
>
> Now, even about only the Java side, something is unclear to me:
> The official documentation of the String class presents .format() as a 
> String method, not as a String constructor.
> 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...
>
> --> jimport java.lang.String
> --> s = String.new()
>  s  =
>
> --> s.length()   // OK, this works
>  ans  =
>   0
>
> --> s.format("%6.2f", -3.1415926)
> Undefined operation for the given operands.
> check or define function %eo_e for overloading.
>
> --> s = String.new("%6.1f")
>  s  =
> %6.1f
>
> --> s.format(-3.1415926)
> Undefined operation for the given operands.
> check or define function %eo_e for overloading.
>
> Yet, the .format method is actually listed among all String's methods:
> --> or(jgetmethods(String)=="format")
>  ans  =
>   T
>
> 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().
>
> Any hint is welcome.
>
> Regards
> Samuel
>
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users

-- 
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
http://www.utc.fr/~mottelet

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20210504/a5e2656a/attachment.htm>


More information about the users mailing list