The PSION Organiser II Homepage
Forum Home Forum Home Help Help Search Search Members Members Login Login Register Register

Welcome, Guest. Please Login or Register.
Why register?
   The Psion Organiser II Forum
   User Forum
   User Post
(Moderator: Mikesan)
   ENG function
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: ENG function  (Read 750 times)
Supergeek
Member




   


Posts: 12
ENG function
« on: Oct 27th, 2002, 4:49am »
Quote Quote Modify Modify

This little code will return a floating point in scientific format but the exponent will be divisible by 3. It is just like the ENG button on a CASIO scientific calculator. Very handy for easy recognition of metric units etc. Returns in string format. It is very slow. Does anybody know how to do this quicker/easier?
 
eng$:(in,dec%)
rem Receive floating point and decimal places
local c%,ex%,temp,s%,out$(16),sign$(1),exp$(2)
if intf(in)=0
 s%=1
 sign$="-"
else
 s%=-1
 sign$="+"
endif
temp=in
c%=0
do
 ex%=c%*s%*3
 temp=in*10**(flt(ex%))
 c%=c%+1
until intf(temp)<1000 and intf(temp)>=1
exp$=gen$(abs(ex%),2)
if len(exp$)=1
 exp$="0"+exp$
endif
out$=fix$(temp,dec%,12)+"E"+sign$+exp$
return out$

Eng$.opl (attachment deleted)
« Last Edit: Oct 27th, 2002, 10:45am by Boris »
POISN
active Member




   


Posts: 48
Re: ENG function
« Reply #1 on: Oct 29th, 2002, 6:43am »
Quote Quote Modify Modify

Another approach would be to start with a string returned by SCI$, then manipulate it. The exponent would only need to be incremented or decremented by one to make it multiple of three. Then the decimal point would only need to be moved left or right by one position, which could be done by swapping it with its neighbour.
 
Example:
 
7.980845970E-04  --> 0.798084597E-03
^^swap  ^^inc   ^prepend "0"
 
 
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

The Psion Organiser II Forum » Powered by YaBB 1 Gold - SP 1.1!
YaBB 2000-2002,
Xnull. All Rights Reserved.
top