|
Post by Walt Decker on Mar 8, 2022 11:36:49 GMT -5
Perhaps working the "skety" code into functions would help remove those pesky criters.
|
|
|
Post by turtleman on Mar 10, 2022 6:12:01 GMT -5
Although it's working, I'm afraid I still don't totally understand the function code. Is there a way to align a column of numbers from the left-hand side (most significant digit) and still insert comma delimiters every three digits from the right?
Whoops – didn't word that too well. The numbers automatically align from the MSD. Just wondering how to insert the commas.
|
|
|
Post by Rod on Mar 10, 2022 8:08:40 GMT -5
Don't understand the question. Please give three examples of the numbers and how you want then displayed.
123,456,123.99 123,456.99
or
123,456,123.99 123,456.99
|
|
|
Post by turtleman on Mar 10, 2022 8:27:02 GMT -5
Sorry for the confusion. Without employing using("####.##", x) at all, numbers align from the left side inside the graphic boxes and expand to the right as needed. In some cases, the decimal isn't used, and the numbers can grow from 1 to as many as 8 or 9 digits. That works fine, but the numbers would be much easier to read if commas were inserted.
So, to answer your question: 123,456,123.99 123,456.99 123,456 12,345 1,234.56 1,234 123 12 1 0 All of the above are good examples.
The mask examples on the previous page were a big help displaying fixed 1 to 3 digit percentages including 2 decimal places. But for strictly cosmetic reasons, it would be great to be able to display the other numbers, as shown, starting from the left-hand side with commas inserted from the left of the decimal, LSD, even if the decimal isn't shown.
|
|
|
Post by alincon on Mar 10, 2022 9:10:08 GMT -5
does this help? Can you see how to change the function for even larger numbers?
a$=using("########.##",-12) print comma$(trim$(a$)) a$=using("########.##",-123) print comma$(trim$(a$)) a$=using("########.##",-1234) print comma$(trim$(a$)) a$=using("########.##",-12345) print comma$(trim$(a$)) a$=using("########.##",-123456) print comma$(trim$(a$)) a$=using("########.##",-1234567) print comma$(trim$(a$)) a$=using("#########.##",-12345678) print comma$(trim$(a$)) a$=using("##########.##",-123456789) print comma$(trim$(a$)) a$=using("##########.##",123456789.1) print comma$(trim$(a$))
wait
function comma$(b$)
if left$(b$,1) = "-" then b$ = mid$(b$,2) x$ = "-" end if if len(b$)>9 then comma$ = left$(b$,(len(b$)-9))+","+mid$(b$,(len(b$)-8),3)+","+right$(b$,6) else if len(b$)>6 then comma$ = left$(b$,(len(b$)-6))+","+right$(b$,6) else comma$=b$ end if end if comma$=space$(15-len(comma$))+comma$ + x$ end function
r.m.
|
|
|
Post by turtleman on Mar 10, 2022 9:22:25 GMT -5
Alincon: Thanks, and I'm sure it's my inexperience, but I don't have a clue! It looks like the same code repeated with different results. I'd like all the numbers to align from the left-hand side. Still trying to figure it out, however.
I added a few more examples to my previous post.
|
|
|
Post by tsh73 on Mar 10, 2022 9:47:14 GMT -5
Point of using same mask was having decimal dot aligned. But if you don't need that you can just TRIM$() extra front spaces.
1.23456124e8 x=1.23456124e8 123,456,123.99 123,456,124 x=1234561.24 1,234,561.24 1,234,561 x=12345.6124 12,345.61 12,346 x=123.456124 123.46 123 x=1.23456124 1.23 1 x=0.12345612e-1 0.01 0
x = 123456123.99 mask1$ = "###,###,###,###.##" mask2$ = "###,###,###,###" while x>0.01 print "x="; x 'print using$(mask1$, x) 'print using$(mask2$, x) print trim$(using$(mask1$, x)) print trim$(using$(mask2$, x)) x=x/100 wend
function using$(mask$, x) delim1000$ = "," 'the point is, we do not print them (print " ") if there are no digit in this place
realMask$ = "" for i = 1 to len(mask$) c$=mid$(mask$,i,1) if instr("#.", c$) then realMask$ = realMask$ + c$ next
x$=using(realMask$, x) 'print x$
xx$="" j = 1 digitStarted=0 for i = 1 to len(mask$) c$=mid$(mask$,i,1) if instr("#.", c$) then cc$=mid$(x$,j,1) xx$ = xx$ + cc$ j=j+1 digitStarted = (instr(" -", cc$)=0) else if instr(delim1000$, c$) then if digitStarted = 0 then if cc$="-" then 'if we have " -," we should convert it to " -" xx$ = left$(xx$, len(xx$)-1) + " " c$="-" else c$=" " 'skip thousand delimiter if digits not started yet end if end if end if xx$ = xx$ + c$ end if next using$ = xx$ end function
|
|
|
Post by turtleman on Mar 10, 2022 10:01:13 GMT -5
Actually, I need both applications – some with decimals aligned and others (with or without decimals) with commas beyond 3-digit numbers. I haven't used trim before (which shows what I know), but it looks like that will do the trick. Will report back after I've had a chance to play with it. Thanks!
|
|
|
Post by Walt Decker on Mar 10, 2022 10:56:34 GMT -5
I think the #######.## is confusing you. The LB function USING("#######.##, Number) can format that just fine. However, the function was not built to accomodate hundreds delimiters so PRINT USING("##,###,###.###", Number) will not produce what you want. Think of it this way. The decimal number 98766.352 can be broken down to two parts, an integer part on the left side of the decimal point and a decimal part on the right side of the decimal point which will be
NumberStr$ = "90755.352" Dot = INSTR(NumberStr$, ".") LeftSide$ = LEFT$(NumberStr$, Dot - 1) RightSide$ = MID$(NumberStr$, Dot + 1)
Divide the length of the left side by 3 to determine the number of 100s groups
NumHundreds = INT(LEN(LeftSide$) / 3) (= 1 group)
Find the number of digits remaining:
Remainder = LEN(LeftSide$) - NumHundreds * 3 (= 2)
Set the delimiter(s) starting with the remaining digits (Remainder)
LeftSide$ = LEFT$(Remainder) + "," + MID$(LeftSide$, Remainder + 1) (= 90,755)
Define where the next hundreds group will be:
Remainder = Remainider + 3 + 1 (add one for the first comma)
FOR I = 1 TO NumHundreds IF LEN(LeftSide$) >= Remainder THEN EXIT FOR
LeftSide$ = LEFT$(LeftSide$, Remainder) + "," + MID$(LeftSide$, Remainder + 1) Remainder = Remainder + 3 + I (have to add for each additional comma) NEXT I
Now you put LeftSide$ and RightSide together
NumberStr$ = LeftSide$ + RightSide$ (90,755.352)
NumberStr$ is what you print.
Now, consider these two numbers:
96.32764 107593.233
How do you get the decimals to line up?
Split them into integer parts and find the maximum length of the integer parts and then pad the shortest length to match the maximum length. You can do that with either zeros or spaces after inserting the hundreds delimiters.
|
|