Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dealing with fractions 1

Status
Not open for further replies.

beedubau

Programmer
Jan 7, 2003
97
AU
The 3rd party control I am using presents Exif shutter speed values as both say 1/60 and 10/600 depending on camera.

As the former is the normal way to present the shutter speed, is there a way to check if the value is in the second form and then convert to the first?.

The output is a chr string.

Regards

Bryan
 
Seems that you will have to evaluate the character string.
Look at whats on the left of the / and whats on the right of the /. Tear it apart and if you need to do math convert the chars to the left and right to numberic and do the math.
Using the AT and SUBS commands will parse it.
 
This code seems to work on thee xamples I have to hand

Code:
FUNCTION CONVERSION

PARAMETERS a



*!eg a = '10/600'- need '1/60'

Y = AT('/',a)

z = SUBSTR(a,1,Y-1)

IF z #'1'

	x = SUBSTR(a,Y+1,LEN(a))

	p = INT(VAL(z))


	q = INT(p/10)
	r = INT(VAL(x))
	s = INT(r/10)

	a = ALLTRIM(STR(q))+'/'+ ALLTRIM(STR(s))

ENDIF

a = a +'  seconds'

RETURN a

can it be improved?

Bryan
 
There does not appear to be an infinite number of shutter speeds, in fact the number is small. You could create a table with tolerances on the nominal decimal value of each speed and search for the speed. In this example , tolerance is 5%


Fraction Decimal
Speed Lower upper

1/125 0.0076 0.0084
1/100 0.0095 0.0105
1/60 0.0158 0.0175
1/30 0.0317 0.0350
 
You did not state the input type.
Beedubau assumed Char,
Here is a Numeric input example

LPARAMETERS lnSec, lnDiv
STORE '' TO lcMessage
STORE '' TO lcReturn
DO CASE
CASE PARAMETERS() < 1 OR VARTYPE(lnSec)<>"N" OR EMPTY(lnSec)
lcMessage = "First Parameter failure"
CASE PARAMETERS() < 2 OR VARTYPE(lnDiv)<>"N" OR EMPTY(lnDiv)
lcMessage = "Second Parameter failure"
OTHERWISE
DO WHILE .T.
IF lnDiv > 1
lnSec = INT(lnSec / 10)
lnDiv = INT(lnDiv / 10)
ELSE
EXIT
ENDIF
ENDDO
lcReturn = TRANSFORM(lnSec / lnDiv)
ENDCASE
*
IF !EMPTY(lcMessage
=MESSAGEBOX(lcMessage)
ENDIF
RETURN lcReturn


David W. Grewe Dave
 
Dave - I did make two changes to get what I wanted

IF lnSec > 1

lcReturn = TRANSFORM(lnSec) +'/'+ TRANSFORM(lnDiv)

Thanks

Bryan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top