[Scilab-users] Java String.format(format, value) within Scilab
Samuel Gougeon
sgougeon at free.fr
Tue May 4 15:44:55 CEST 2021
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 <http://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://docs.oracle.com/javase/7/docs/api/java/lang/String.html> class
and its .format() method
<https://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://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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20210504/bc51ec4d/attachment.htm>
More information about the users
mailing list