Scientific+Using

Scientific USING function
JB can input numbers in scientific format, like 1.23e4. However, there are no build-in way to force number output in this form. Below the function that does just that, with required number of digits after decimal separator. //(keep in mind that there are no more then 16 digits stored in real number (Double data type)).//

I remember seeing another approach by DAVEG (for LB may be?), but I was not able to find it again. If someone could find it, please post a link.

See also **note about shotrtcuts**

note about shotrtcuts
I've got a mail about this page: > //I have never seen and do not understand the use of the condition or order relation statements as part of arguments of functions, like usingS$(x,p<0), and other such things. I can only understand these://

> //p<0 can be either true or false//

> //IF p<0 THEN... p being less than zero leads to a piece of code or instruction and p not being less than zero leads to continuation or to different piece of code or instruction//

> //So then explain maybe how your new usingS$ function works and how does a person read your code which uses the relation or conditional expressions in what seem to be unusual ways?//

So here is my explanation: yes, p<0 can be either true or false ... logically. But JB has no boolean type, and all relational operators return exactly 0 (for False) or 1 (for true). So, > means s$ gets "-" if condition holds or "" (empty) if not, and > means "And if log10<0, subtract 1".

Of cource it could be programmed with If's, but this way it works too (and it's a bit shorter).

code format="lb" 'scientific USING function, usage example n = 123.456 print n, usingS$(n,3) print n, usingS$(n,0) n = 7623.456 print n, usingS$(n,0) n = 123.456/1e6 print n, usingS$(n,3) n = -7623.456 print n, usingS$(n,0) n = -123.456/1e6 print n, usingS$(n,3) n = 1.456464 print n, usingS$(n,3) n = 1.4 print n, usingS$(n,3) n = 0.14 print n, usingS$(n,3) n = 0.014 print n, usingS$(n,3) n = 0 print n, usingS$(n,3)

'scientific USING function. '(keep in mind that there are no more then 16 digits stored in real number (Double data type)). function usingS$(n,prec) if n = 0 then usingS$="0e+0":exit function fmt$ = "#"+left$(".",prec>0)+left$("#################",prec)  'fmt of mantissa s$=left$("-",n<0) n=abs(n) log10=log(n)/log(10) e=int(log10)-(log10<0)   'QB like INT. Makes mantissa for negative exponents start from digit (not 0 as JB do) p=10^e if left$(using(fmt$,n/p),1)="%" then p=p*10:e = e+1 usingS$=s$+using(fmt$,n/p) +"e"+left$("+",e>0) +str$(e)  'Excel always shows "+" for exponent End function code