joeg
New Member
Posts: 22
|
Post by joeg on Oct 11, 2022 15:35:11 GMT -5
I'd like to format a resulting negative number via the USING() statement, if possible. Positive numbers have no issues.
For example (with negative result): L= 54.11 - 56 PRINT L 'PRINTS THE NEGATIVE NUMBER WITHOUT FORMATTING APPLIED
L$=USING("##.##",L) L=VAL(L$) PRINT L 'PRINTS 0
What rule(s) am I violating?
|
|
|
Post by Walt Decker on Oct 11, 2022 15:58:53 GMT -5
L = 54.11 - 56 PRINT USING("###.###", L) L$ = USING("###.###", L) PRINT L$
|
|
joeg
New Member
Posts: 22
|
Post by joeg on Oct 11, 2022 16:23:37 GMT -5
Thank you! Not enough ### leading symbols. One must be needed by the sign. What does the leading % mean when that is present (not that it is showing up now)?
|
|
|
Post by Walt Decker on Oct 11, 2022 16:27:33 GMT -5
Means the format string is not large enough to accomodate the value of its target, E. G: NumDec = -1234.567 PRINT USING("###.###", NumDec)
EDIT: You can obtain a reasonable format string for the above by using the functions I recently placed in the "Libery BASIC code" thread topic "Share Your Snipped II".
|
|
joeg
New Member
Posts: 22
|
Post by joeg on Oct 11, 2022 16:34:40 GMT -5
Thank you. Follow-up question - Does the USING() command support forcing a $ into the output like GW-BASIC does? If not, what's the best practice to formatting the output with a leading "$"?
Example in GW-BASIC: PRINT USING "$$###.##";456.78 $456.78
|
|
|
Post by Walt Decker on Oct 11, 2022 16:39:02 GMT -5
No.
Dollor = 456.78 DolStr$ = USING("###.##", Dollor) DolStr$ = "$" + DolStr$ PRINT DolStr$
|
|
joeg
New Member
Posts: 22
|
Post by joeg on Oct 11, 2022 16:43:38 GMT -5
Interesting! I like the logic challenge of coming up with that workaround solution. Thanks once again!
|
|
|
Post by Walt Decker on Oct 11, 2022 16:54:41 GMT -5
FYI, USING() will not split a number into 100s either. I do have a dll that will format number in multiple ways, but the input is rather complicated.
You can obtain a reasonable format string by using the functions I recently placed in the "Libery BASIC code" thread topic "Share Your Snippets II". There is also a function that will split a number into 100s. It is all native LB.
|
|
|
Post by Brandon Parker on Oct 13, 2022 20:58:17 GMT -5
Another thing that might be useful is the ability to remove/suppress the "%" Over/Underrun indicator and trim the result if desired.
Global False : False = 0 Global True : True = 1
var= 54.11 - 57
Print suppressOverflow$(var, True) Print Using("###.###", var) End
Function suppressOverflow$(value, trim) suppressOverflow$ = Using("###.###", value) suppressOverflow$ = Mid$(suppressOverflow$, (Instr(suppressOverflow$, "%") + 1)) If trim Then suppressOverflow$ = Trim$(suppressOverflow$) End Function
{:0)
Brandon Parker
|
|
joeg
New Member
Posts: 22
|
Post by joeg on Oct 14, 2022 18:38:46 GMT -5
Nice! Thank you, Brandon!
|
|