What do you like to use for adding commas to numerical output?
#2
Something a bit more optimized.

Code: (Select All)
DO
    INPUT a
    a$ = LTRIM$(STR$(a))
    j = 4
    DO UNTIL j / 4 >= LEN(LTRIM$(STR$(ABS(a)))) / 3
        a$ = MID$(a$, 1, LEN(a$) + 1 - j) + "," + MID$(a$, LEN(a$) + 1 - j + 1)
        j = j + 4
    LOOP
    PRINT a$
LOOP

Of course for very large numbers this would have to be tweaked to exclude numeric input, and just use string math.

Code: (Select All)
DO
    LINE INPUT a$
    x = LEN(a$) : IF LEFT$(a$, 1) = "-" THEN x = x - 1
    j = 4
    DO UNTIL j / 4 >= x / 3
        a$ = MID$(a$, 1, LEN(a$) + 1 - j) + "," + MID$(a$, LEN(a$) + 1 - j + 1)
        j = j + 4
    LOOP
    PRINT a$
LOOP

Pete
If eggs are brain food, Biden takes his scrambled.
Reply


Messages In This Thread
RE: What do you like to use for adding commas to numerical output? - by Pete - 05-22-2022, 06:47 AM



Users browsing this thread: 3 Guest(s)