Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikibooksThe Free Textbook Project
Search

Programming Gambas from Zip/Formatting

From Wikibooks, open books for an open world
<Programming Gambas from Zip

Formatting

[edit |edit source]

These examples may vary depending on the regional settings on your computer (for time, date and currency).

Formatting Numbers

[edit |edit source]

Example: Label1.text = Format(123456.789, ",#.00") shows as 123,456.79

Format(123456.789) shows as if you usedgb.Standard

http://Gambaswiki.org/wiki/cat/constant

Formatting Constants

[edit |edit source]
gb.StandardUsesgb.GeneralNumber for formatting numbers andgb.GeneralDate for formatting dates and times.
gb.GeneralNumberWrites a number with twelve decimal digits. Uses scientific format if its absolute value is lower than 10-4 (0.0001) or greater than 107 (1 million).
gb.FixedEquivalent to "0.00"
gb.PercentEquivalent to "###%"
gb.ScientificWrite a number with its exponent (power of ten) and eighteen decimal digits.

Symbols in the Format Strings

[edit |edit source]

Symbols other than these print as they appear. For example, $ prints as is.

+Print the sign of the number.Format(Pi, "+#.###")+3.142
-Print the sign of the number only if it is negative.Format(Pi, "-#.###")3.142
#Print a digit only if necessary.

One # before the decimal point is all that is needed. After the decimal point, as many #’s as you want decimal places.

Format(123.456789, "#.###")123.457
0Always print a digit, padding with a zero if necessary.Format(24.5, "$#.00")$24.50
.Print the decimal pointFormat(123.456, "#.0")123.5
,Separate the thousandsFormat(1234567890, "#,")

Format(1234567890, ",#")

1,234,567,890
%Multiply the number by 100 and print a percent sign.Format(0.25, "#%")25%
EThis isScientific Notation, which is

“Something-times-ten-to-the-power-of-something”.

“E” means “times ten to the power of...”

1.2E+3 means "Start with 1.200, then move the decimal point three places to the right (get bigger x 1000) to become 1200."

Negative numbers after the “E” mean move the decimal point to the left.

Format(1234.5, "#.#E##")

Format(0.1234, "#.#E##")

1.2E+3

1.2E-1

$The national currency symbol (according to the country as set on your computer)Format(-1234.56, "$,#.###")-$1,234.56
$$The international currency symbol (according to the country as set on your computer)Format(-1234.56, "$$,#.###")-AUD 1,234.56
( )Negative numbers represented with brackets, which is what finance people use.Format(-123.4, "($$,#.00)")(AUD 123.40)

Formatting Dates

[edit |edit source]

Example: Format(Now, gb.Standard) shows as10/07/2019 21:07:26

Formatting Constants

[edit |edit source]
gb.GeneralDateWrite a date only if the date and time value has a date part, and write a time only if it has a date part. Writes nothing for anull date or a short time when there is no date, and writes the date and time for all other cases.Format(Now, gb.GeneralDate) is 10/07/2019 21:17:45
gb.StandardUsesgb.GeneralNumber for formatting numbers andgb.GeneralDate for formatting dates and times.10/07/2019 21:20:45
gb.LongDateLong date formatWednesday 10 July 2019
gb.MediumDateMedium date format10 Jul 2019
gb.ShortDateShort date format10/07/2019
gb.LongTimeLong time format21:22:35
gb.MediumTimeMedium time format09:23 PM
gb.ShortTimeShort time format21:23

Format String Symbols

[edit |edit source]

Label1.text =Format(Now, "dddd dd/mm/yyyy hh:nn:ss") shows asTuesday 09/07/2019 20:45:13

yyThe year in two digitshThe hour
yyyyThe year in four digitshhThe hour in two digits.
mThe monthnThe minutes.
mmThe month in two digits.nnThe minutes in two digits
mmmAbbreviated monthsThe seconds
mmmmFull name of the monthssThe seconds in two digits
dThe day:The time separator
ddThe day in two digitsuA point and the milliseconds, if non-zero
dddAbbreviated weekdayuuA point and the milliseconds in three digits.
ddddFull name of the weekdaytThe timezone alphabetic abbreviation
/The date separatorttThe timezone in HHMM format
AM/PMThe AM or PM symbol

Formatting Currency

[edit |edit source]

For the symbols in a format string, see above (numbers).

gb.CurrencyUses the national currency symbol.Format(14.50, gb.Currency)

shows as$ 14.5

gb.InternationalUses the international currency symbol.Format(14.50, gb.International)

shows asAUD 14.5

Programming Gambas from Zip
 ← DataTypesFormattingOperatorPrecedence → 
Retrieved from "https://en.wikibooks.org/w/index.php?title=Programming_Gambas_from_Zip/Formatting&oldid=3562943"
Category:

[8]ページ先頭

©2009-2025 Movatter.jp