I am posting this in the hope that it will be of assistance to some of you.
I am developing a scientific application and needed a significant figure script. There did not seem to be one on this message board... so I created one that seems to work (NO GUARANTEES THOUGH!).
Actually, there are 2 scripts; one returns a string and the other returns a number.
Hope they are of some use.
PS If anyone knows how to deal with very small numbers in Alpha V4.5 I would be interested... (I suppose I could interject a scalar prior to calc & then divide after calc).
function SigFig as N(Number as N,SigFigReqd as N)
DIM NumAbs As N
select
case Number=0
SigFig=0
case Number=1,-1,0))*10^INT(LOG(NumAbs)/2.302585)
SigFig=SigFig*-1.0
case Number>0
SigFig=ROUND(Number/10^INT(LOG(Number)/2.302585),SigFigReqd+IF(Number>=1,-1,0))*10^INT(LOG(Number)/2.302585)
end select
end function
or... as string...
function SigFigStr as C(Number as N,SigFigReqd as N,Decimal as N)
' David Boomer 416 339-2227
' oops this does not work for small numbers eg 0.0000125242 ?? it seems that alpha only allows 6 decimal places!!
DIM NumAbs As N
DIM SigFig As N
select
case Number=0
SigFigStr="0."+Replicate("0",Decimal)
case Number=1,-1,0))*10^INT(LOG(NumAbs)/2.302585)
SigFig=SigFig*-1.0
SigFigStr=Str(SigFig,12,Decimal)
case Number>0
SigFig=ROUND(Number/10^INT(LOG(Number)/2.302585),SigFigReqd+IF(Number>=1,-1,0))*10^INT(LOG(Number)/2.302585)
SigFigStr=Str(SigFig,12,Decimal)
end select
end function
I am developing a scientific application and needed a significant figure script. There did not seem to be one on this message board... so I created one that seems to work (NO GUARANTEES THOUGH!).
Actually, there are 2 scripts; one returns a string and the other returns a number.
Hope they are of some use.
PS If anyone knows how to deal with very small numbers in Alpha V4.5 I would be interested... (I suppose I could interject a scalar prior to calc & then divide after calc).
function SigFig as N(Number as N,SigFigReqd as N)
DIM NumAbs As N
select
case Number=0
SigFig=0
case Number=1,-1,0))*10^INT(LOG(NumAbs)/2.302585)
SigFig=SigFig*-1.0
case Number>0
SigFig=ROUND(Number/10^INT(LOG(Number)/2.302585),SigFigReqd+IF(Number>=1,-1,0))*10^INT(LOG(Number)/2.302585)
end select
end function
or... as string...
function SigFigStr as C(Number as N,SigFigReqd as N,Decimal as N)
' David Boomer 416 339-2227
' oops this does not work for small numbers eg 0.0000125242 ?? it seems that alpha only allows 6 decimal places!!
DIM NumAbs As N
DIM SigFig As N
select
case Number=0
SigFigStr="0."+Replicate("0",Decimal)
case Number=1,-1,0))*10^INT(LOG(NumAbs)/2.302585)
SigFig=SigFig*-1.0
SigFigStr=Str(SigFig,12,Decimal)
case Number>0
SigFig=ROUND(Number/10^INT(LOG(Number)/2.302585),SigFigReqd+IF(Number>=1,-1,0))*10^INT(LOG(Number)/2.302585)
SigFigStr=Str(SigFig,12,Decimal)
end select
end function