A mm is 0.03936996 inches. or approximately 0.04 inches so if you multiply the mm by 2.54 (or do successive adds) you can get tenths of an inch without the decimal.
If you are doing this in floating point multiply the mm by 10 or 100 and divide by the same amount after the conversion is done.
to tenths:
inch10 = mm ** 25802 ' good up to 65536mm
to hundredths:
inch100 = mm * 10 ** 25802 ' good up to 6553mm
to thousandths
inch1000 = mm * 100 ** 25802 ' good up to 655mm
example
mm = 25
inch1000 = 984 ' meaning 0.984 inch true value 0.984251968505
** 25802 using the PBASIC ** operator.is equivalent to 25802/65536 = ~0.3934
I'm very rusty in PBASIC but this was the output when entering 88 mm.
Please enter millimeters: 88
88 mm = 3.5 in
Please enter millimeters:
Here's the program:
' {$STAMP BS2}
' {$PBASIC 2.5}
CONVERSION CON 254
ROUNDING CON 127
SCALE100 CON 100
millimeters VAR Word
inches VAR Word
tenthsOfInches VAR Word
Main:
DO
DEBUG CR, "Please enter millimeters: " ' prompt user
DEBUGIN NUM millimeters ' retrieve number
tenthsOfInches = ((millimeters * SCALE100) + ROUNDING) / CONVERSION
inches = tenthsOfInches / 10
tenthsOfInches = tenthsOfInches - (10 * inches) ' I don't remember how to do modulus with BS.
DEBUG DEC millimeters, " mm = ", DEC inches, ".", DEC tenthsOfInches, " in"
PAUSE 1000 ' wait one second
LOOP ' repeat forever
Unfortunately the word size variables in PBASIC don't lend themselves to doing math with large numbers. I bet a much better program could be written using the tricks Tracy showed us.
Comments
If you are doing this in floating point multiply the mm by 10 or 100 and divide by the same amount after the conversion is done.
inch10 = mm ** 25802 ' good up to 65536mm
to hundredths:
inch100 = mm * 10 ** 25802 ' good up to 6553mm
to thousandths
inch1000 = mm * 100 ** 25802 ' good up to 655mm
example
mm = 25
inch1000 = 984 ' meaning 0.984 inch true value 0.984251968505
** 25802 using the PBASIC ** operator.is equivalent to 25802/65536 = ~0.3934
I'm very rusty in PBASIC but this was the output when entering 88 mm.
Here's the program:
Unfortunately the word size variables in PBASIC don't lend themselves to doing math with large numbers. I bet a much better program could be written using the tricks Tracy showed us.