Can I use commas to sperate thousands and millions in ZPL with the FORMAT keyword?
For example, I want the number 123456789 to be formatted as 123,456,789.
Best answer by David Nguyen
View originalBest answer by David Nguyen
View original
# Define a number
a_number = 123456789
# Print the number
PRINT "Input number = ", a_number
PRINT "Calling formatting sub-macro..."
PRINT ""
PRINT "Formatted number = ",
# Define the number as an input for the sub-macro
CALLSETDBL 1, a_number
# Call the formatting sub-macro
CALLMACRO Comma_separation.ZPL
# Retrieve input number
a_number = CALD(1)
# Change format to 3 digits integer
FORMAT 3 INT
# If input number is smaller than 1000 ...
IF (a_number > 999)
# and if input number is smaller than 1000000 ...
IF (a_number > 999999)
a_string$ = $STR(a_number)
a_string$ = $RIGHTSTRING(a_string$, 6)
# ... otherwise, we print the millions, add a coma
PRINT $STR(a_number/999999), ",",
# print the thousands, add another coma
PRINT $LEFTSTRING(a_string$, 3), ",",
# and then print the rest
PRINT $RIGHTSTRING(a_string$, 3)
ELSE
a_string$ = $STR(a_number)
# ... we first print the thousands, add a coma
PRINT $STR(a_number/1000), ",",
# and then print the rest
PRINT $RIGHTSTRING(a_string$, 3)
ENDIF
ELSE
# ... we just print that number
PRINT a_number
ENDIF
Actually, I can't find a C format spec for this...I'm really surprised!
FORMAT "C_format_string" [lit]
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.