[kepler-dev] [Ptolemy] how to remove scientific notation in Ptolemy/Kepler?

Jianwu Wang jianwu at sdsc.edu
Sun Dec 12 17:25:56 PST 2010


Hi Christopher,

     Thanks. I'll build an actor for it.

Best wishes

Sincerely yours

Jianwu Wang
jianwu at sdsc.edu
http://users.sdsc.edu/~jianwu/

Assistant Project Scientist
Scientific Workflow Automation Technologies (SWAT) Laboratory
San Diego Supercomputer Center
University of California, San Diego
San Diego, CA, U.S.A.


On 12/12/2010 4:41 PM, Christopher BROOKS wrote:
> Hi Jianwu,
> I don't know of a function that will do this.
> A model that illustrates the problem would be of use.
>
> ptolemy.data.DoubleToken.toString() is what controls this:
>
>          if (Double.isNaN(_value) || Double.isInfinite(_value)) {
>              return Double.toString(_value) + unitString;
>          } else {
>              double mag = Math.abs(_value);
>
>              if ((mag == 0.0) || ((mag<  1000000)&&  (mag>  .001))) {
>                  return TokenUtilities.regularFormat.format(_value) +
> unitString\
> ;
>              } else {
>                  return TokenUtilities.exponentialFormat.format(_value)
>                          + unitString;
>              }
>          }
>
>
> That code is over 10 years old, the change log says:
>
> r11668 | vogel | 2000-05-13 20:04:04 -0700 (Sat, 13 May 2000) | 4 lines
>
> Fixed performance bug. Two instances of DecimalFormat were being created
> on init, which is very expensive. I moved the instantiation of
> DecimalFormat
> objects into the toString() method.
>
> ------------------------------------------------------------------------
> r11522 | neuendor | 2000-05-04 17:27:07 -0700 (Thu, 04 May 2000) | 2 lines
>
> improved toString method.
>
> ------------------------------------------------------------------------
> r11506 | liuj | 2000-05-03 14:57:12 -0700 (Wed, 03 May 2000) | 2 lines
>
> fix the string format
>
> ------------------------------------------------------------------------
> r11496 | neuendor | 2000-05-01 17:48:15 -0700 (Mon, 01 May 2000) | 4 lines
>
> toString method of Tokens now always returns something that can be parsed
> by the expression language.  (Except for ObjectToken, which is not yet
> implemented)
>
>
>
> Perhaps an actor that reads in DoubleTokens and always generates either
> scientific or non-scientific text would be a good workaround?  It seems
> like
> changing DoubleToken would result in what you want.
>
> You could also experiment with trying to access the static fields in the
> TokenUtilities
> class from within the Expression language.  The expression language allows
> access of static methods, see
> http://ptolemy.eecs.berkeley.edu/ptolemyII/ptIIlatest/ptII/doc/expressionsa8.htm
>
> However, what we want to do is to access a static field.  I think the
> easiest
> way to do this would be to edit ptolemy.data.expr.Constants and add the
> two fields
> from TokenUtilities.  Ideally, these would have unique names that would
> not
> conflict with preexisting code.  Then, you could access the constants by
> name
> and possibly call the appropriate methods.  Still, I think it would be
> easier to
> write actors that do this.
>
> _Christopher
> On Sun, 12 Dec 2010 16:12:16 -0800, Jianwu Wang<jianwu at sdsc.edu>  wrote:
>> Hi All,
>>
>>       I use 'Expression' in Ptolemy to generate a double number, it is
>> automatically converted to scientific notation. It is the same behavior
>> if I use actors such as 'Add or Subtract' and 'Multiple or Divide'. I
>> know it is correct based on Double.toString()
>>
> http://download.oracle.com/javase/6/docs/api/java/lang/Double.html#toString%28double%29.
>> But I wonder how can I easily get rid of scientific notation. Is there
>> any actor for this function or any function in 'Expression' to do it?
>>
>>       Thanks.
> _______________________________________________
> Ptolemy maillist  -  Ptolemy at chess.eecs.berkeley.edu
> http://chess.eecs.berkeley.edu/ptolemy/listinfo/ptolemy


More information about the Kepler-dev mailing list