Enjoy the fun of physics with simulations!

Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/

Title: how to make a Ejs way to recognize that a number is 10,100,1000 etcPost by: lookang on March 28, 2009, 11:10:47 am
how to make a Ejs way to recognize that a number is 10,100,1000 etc
if number is 1000 to 9999 , how to display 1000 ? so if a number is 100 to 999, how to display 100 ? if the number is 10 to 99, how to display 10 number 0 to 9 display as 1 ? thanks! Title: Re: how to make a Ejs way to recognize that a number is 10,100,1000 etcPost by: Fu-Kwun Hwang on March 28, 2009, 10:22:38 pm
Your question is not limited to EJS. It is a general question related to mathematics and programming.
3≦log _{10}(x)<4 if 1000_{10}(x)<3 if 100However, java did not provide function for log _{10}(x).It only provide nature log, i.e. ln(x). log _{10}(x)= log_{e}(x)/log_{e}(10)and Math.pow(a,b) will return a ^{b}The following formula should give you what you want. Code: y=(int)(Math.pow(10,(int)(Math.log(x)/Math.log(10.)+1.e-8))); 1.e-8 was added due to possible numerical error.Title: Re: how to make a Ejs way to recognize that a number is 10,100,1000 etcPost by: lookang on March 30, 2009, 10:24:15 am
excellent help.
Code: scaffold=(int)(Math.pow(10,(int)(Math.log(i2)/Math.log(10.)+1.e-8))); i assign my own variables ( scaffold and i2) substitution to modify. thanks for the programming tip. i read a bit before on Math.pow(a,b) which is a ^{b}so what you suggested is 10 ^{(i2/log10 +1.e-8)}Title: Re: how to make a Ejs way to recognize that a number is 10,100,1000 etcPost by: Fu-Kwun Hwang on March 30, 2009, 10:37:50 am
What I suggest is 10
^{(log(i2)/log(10))+1.e-8} |