Another custom macro to truncate decimal places

By Tom Sorrentino


I was reading "The Optional Stop newsletter, Issue 85", particularly the "Macro Maven: Rounding or truncating to a specific number of decimal places" article.


This seems to be a long method of doing this task. Below is what I found that does the same functions, but in a simpler method (below SET V).


I've added features of input checking. See M set below for example. It will be read as M0.

  • O0100

  • #121=3.68256

  • G65 P1000 S#121 M-0.5 D3 V100

  • M30

The custom macro:

  • O1000

  • (---INPUT-CHECKS---)

  • #13=[FIX[ABS[#13]]]

  • (GET POSITIVE INTEGER OF M#13 REGARDLESS OF INPUT)

  • IF [#13EQ#0] THEN #3000=101

  • (M-NOT-DEFINED)

  • IF [#13LT0] OR [#13GE2] THEN #3000=102

  • (M-OUT-OF-RANGE)

  • #7=[FIX[ABS[#7]]]

  • (GET POSITIVE INTEGER OF D#7 REGARDLESS OF INPUT)

  • IF [#7EQ0] OR [#7EQ#0] THEN #3000=102

  • (D-NOT-DEFINED)

  • IF [#7LT1] OR [#7GE5] THEN #3000=103

  • (D-OUT-OF-RANGE)

  • #22=[FIX[ABS[#22]]]

  • (GET POSITIVE INTEGER OF V#22 REGARDLESS OF INPUT)

  • IF [#22EQ0] OR [#22EQ#0] THEN #3000=104

  • (V-NOT-DEFINED)

  • IF [#22LT100] OR [#22GE149] THEN #3000=105

  • (V-OUT-OF-RANGE)

  • (DETERMINE D VALUE)

  • IF [#7EQ1] THEN #102=10

  • (USE 10 FOR 0.X0000)

  • IF [#7EQ2] THEN #102=100

  • (USE 100 FOR 0.0X000)

  • IF [#7EQ3] THEN #102=1000

  • (USE 1000 FOR 0.00X00)

  • IF [#7EQ4] THEN #102=10000

  • (USE 10000 FOR 0.000X0)

  • (SET V)

  • IF [#13EQ0] THEN #[#22]=[FIX[#19*#102]/#102]

  • (ROUNDUP)

  • IF [#13EQ1] THEN #[#22]=[FUP[#19*#102]/#102]

  • (TRUNCATED)

  • GOTO 9999

  • (NOTES)

  • (S=VALUE TO BE ALTERED)

  • (M=0-TRUNCATED, M=1-ROUNDEDUP)

  • (D=DECIMAL PLACE TO WORK TO)

  • (V=VARIBLE TO PLACE RESULT)

  • (G65 P1000 S#121 M1.0 D2.0 V100.0)

  • N9999

  • M99


cnc reverse logo.jpg
0

44 Little Cahill Road

Cary, IL  60013

Ph: 847-639-8847

  • Facebook Social Icon