NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/
September 21, 2018, 07:28:30 pm *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Knowledge and practice are one. ..."Wang Yang Ming (1472-1529, Chinese Philosopher) "
Google Bookmarks Yahoo My Web MSN Live Netscape Del.icio.us FURL Stumble Upon Delirious Ask FaceBook

Pages: [1]   Go Down
  Print  
Author Topic: in ejs how to show to number as a power of 10?  (Read 10270 times)
0 Members and 1 Guest are viewing this topic. Click to toggle author information(expand message area).
Fred Chuit
Newbie
*
Offline Offline

Posts: 18



«
Embed this message
on: July 23, 2008, 01:39:08 am »

Dear Sir,

I am just starting to build applets with ejs, it's a wonderful program.
I would like some numbers (double) to be shown on screen as a power of 10.
For instance:
23000 as: 2,3•10^4  (if possible 4 as exponent)
0,00356 as: 3,6•10^-3 (-3 as exponent).

Further, is there a way to have a numberfield also accept(and show) the "," instead of the"."?
So: 34,5 instead of 34.5

It would be great if I could get some simple examples to solve this problems.
Already many thanks for the help.
Greetings,
Fred
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #1 on: July 23, 2008, 01:37:22 pm » posted from:Taipei,T\'ai-pei,Taiwan

Registed user can get files related to this applet for offline access.
Problem viewing java?Add http://www.phy.ntnu.edu.tw/ to exception site list
If java program did not show up, please download and install latest Java RUN TIME

This is what I will do: define a function to convert your value to a string.

For example: define variables in the model
e (double): 1.602e-19
s (String): d2s(v)  // to be used to show e as a String

public String d2s(double v){
 double a;
 int b;
 String o;
 b=(int)(Math.log(v)/Math.log(10.)); // get the value as power of 10
 if(b<0)b=b-1;
 a=d2v(v/Math.pow(10,b));
 o=a+"";
 return o.replace(".",",")+"*10^{"+b+"}";  // convert "." to ","
}
public double d2v(double v){//  for 3 digits displayed max.
 double dv;
 if(v>0)dv=0.5;
 else if(v<0)dv=-0.5;
 else dv=0;
 return (int)(v*1000+dv)/1000.;
}

Add a Text element into DrawingPanel, and set it's text to %s%
You should be able to find 1.602*10-19 in the drawingPanel when you run it.

EJS support (^ or _) for  (superscript or subscript) . Try it at title for PlotingPanel, text element. etc.

I also found "." will be switch to "," for value displayed in slider/Bar/...  when you switch locale from en_EN to es_ES. (I think it will work the same if you select the right locale before running EJS).





Registed user can get files related to this applet for offline access.
Problem viewing java?Add http://www.phy.ntnu.edu.tw/ to exception site list
If java program did not show up, please download and install latest Java RUN TIME
Logged
Fred Chuit
Newbie
*
Offline Offline

Posts: 18



«
Embed this message
Reply #2 on: July 23, 2008, 03:18:56 pm »

Dear mr. Fu-Kwun Hwang,

Many thanks for you advice and help!
This really solves the problem, I couldn't fix.

Again, thanks for your fast reply!
Greetings from Holland,
Fred
Logged
Pages: [1]   Go Up
  Print  
Knowledge and practice are one. ..."Wang Yang Ming (1472-1529, Chinese Philosopher) "
 
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.13 | SMF © 2006-2011, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.14 seconds with 22 queries.since 2011/06/15