USING$ returns a string converted from a number using a specified format.
Syntax:RetStr = USING$(FormatStr AS STRING, Number) Return Value:
Parameters:
|
If the format string contains a "^" character, USING$ will return a scientific notation version of its numeric argument and any other characters contained in the format string will be ignored. Although USING$ will accept an LDOUBLE, that parameter is always cast, internally, to a DOUBLE before being returned as a scientific notation string.
PRINT USING$("^", ATN(1) * 4) PRINT USING$("^", 12345678.12345678)
3.141592653589793E+00 1.234567812345678E+07
PRINT USING$("###.##$", 33.5) PRINT USING$("###.##%", 99.99)
$33.50 99.99%
DIM A$ A$ = USING$("###.#",-1.123456789) : PRINT A$ A$ = USING$("###.##",1.123456789) : PRINT A$ A$ = USING$("###.###",1.123456789) : PRINT A$ A$ = USING$("###.####",1.123456789) : PRINT A$ A$ = USING$("###.######",1.123456789) : PRINT A$ A$ = USING$("###.#######",1.123456789) : PRINT A$ A$ = USING$("###.########",1.123456789) : PRINT A$ A$ = USING$("###.#########",1.123456789) : PRINT A$ A$ = USING$("###.##########",1.123456789) : PRINT A$ A$ = USING$(" ###.#",1.123456789) : PRINT A$ A$ = USING$(" ###.##",1.123456789) : PRINT A$ A$ = USING$(" ###.###",1.123456789) : PRINT A$ A$ = USING$(" ###.####",1.123456789) : PRINT A$ A$ = USING$(" ###.######",1.123456789) : PRINT A$ A$ = USING$(" ###.#######",1.123456789) : PRINT A$ A$ = USING$(" ###.########",1.123456789) : PRINT A$ A$ = USING$(" ###.#########",1.123456789) : PRINT A$ A$ = USING$(" ###.#########",1.123456789) : PRINT A$
-1.1
1.12
1.123
1.1235
1.123457
1.1234568
1.12345679
1.123456789
1.1234567890
1.1
1.12
1.123
1.1235
1.123457
1.1234568
1.12345679
1.123456789
1.123456789
Zeros can be used inside the format string to LEFT pad the resulting string with zeros. Commonly useful for formatting time and date strings but not limited to those.
PRINT USING$("###.##", PI) ' Normal, no LEFT padding occurs PRINT USING$(" #.####", PI) ' Explicit LEFT padding (spaces) PRINT USING$("000.000000", PI) ' Pad 2 zeros on LEFT side of PI PRINT USING$("0000.########", PI) ' Pad 3 zeros on LEFT side of PI
3.14 3.1416 003.141593 0003.14159265
The BCX FORMAT$ function provides basic number formatting capabilities similar to the VB and PowerBasic FORMAT$ function. It takes a numeric value and a mask string and produces a formatted output string.
Syntax:RetStr = FORMAT$(Number [, FormatStr AS STRING]) Return Value:
Parameters:
|
PRINT FORMAT$(123.45, "000.00") ' → "123.45"
PRINT FORMAT$(9.123456789) ' → "9.123457"👉 If the FormatStr mask is empty, the function uses "%.6Lg" format with trailing zeros removed.
PRINT FORMAT$(5.1, "000.00") ' → "005.10"
PRINT FORMAT$(123.45, "###.##") ' → "123.45" PRINT FORMAT$(5.1, "###.##") ' → "5.1"
PRINT FORMAT$ uses LDOUBLE internally for maximum precision. Output is limited to 256 characters.
PRINT FORMAT$(9.123456789) ' → "9.123457" PRINT FORMAT$(PI, "0.000000000000000") ' → "3.141592653589793" PRINT FORMAT$(123.45, "000.00") ' → "123.45" PRINT FORMAT$(5.1, "000.00") ' → "005.10" PRINT FORMAT$(123.45, "###.##") ' → "123.45" PRINT FORMAT$(5.1, "###.00") ' → "5.10" PRINT FORMAT$(123.45, "(+0.00)") ' → "(123.45)" PRINT FORMAT$(-123.45, "(+0.00)") ' → "(-123.45)" PRINT FORMAT$(123.45, " +0.00") ' → " 123.45" PRINT FORMAT$(-123.45, " +0.00") ' → "-123.45" PRINT FORMAT$(123.45, "+0.00") ' → "+123.45" PRINT FORMAT$(1234567.89, "#,##0.00") ' → "1,234,567.89" PRINT FORMAT$(1234, "#,##0") ' → "1,234" PRINT FORMAT$(1234.5, "0.00E+00") ' → "1.23E+03" PRINT FORMAT$(-0.00123, "0.00e-00") ' → "-1.23e-03" PRINT FORMAT$(123, "0000") ' → "0123" PRINT FORMAT$(123, " 000") ' → " 123" PRINT FORMAT$(12, "0000") ' → "0012" PRINT FORMAT$(-123, "*0000") ' → "-123" PRINT FORMAT$(1234, "*0000") ' → "1234" PRINT FORMAT$(5.1, "000.00") ' → "005.10" PRINT FORMAT$(5.1, "###.##") ' → "5.1" PRINT FORMAT$(123.789, "000") ' → "124" PRINT FORMAT$(1234567.89, "#,##0.00") ' → "1,234,567.89" PRINT FORMAT$(1234, "#,##0") ' → "1,234" PRINT FORMAT$(0.1234, "0.00%") ' → "12.34%" PRINT FORMAT$(1.5, "#.#%") ' → "150%" PRINT FORMAT$(0.0001, "0.0000") ' → "0.0001" PRINT FORMAT$(999999999.99, "#,##0.00") ' → "999,999,999.99"