Format Method Specifiers
The following tables list some of the format specifiers you can use with the StringUtils format methods.
General characters
Character |
Format |
Description |
C or c |
Currency |
Currency format. |
D or d |
Decimal |
Displays a string using decimal digits preceded by a minus sign if negative. |
E or e |
Exponential/scientific notation |
Displays numbers in the form ±d.ddddddE±dd where d is a decimal digit. |
F or f |
Fixed point |
Displays a series of decimal digits with a decimal point and additional digits. |
G or g |
General format |
Displays either as a fixed-point or scientific notation based on the size of the number. |
N or n |
Number format |
Similar to fixed point but uses a separator character (such as ,) for groups of digits. |
P or p |
Percentage |
Multiplies the number by 100 and displays with a percent symbol. |
R or r |
Roundtrip |
Formats a floating-point number so that it can be successfully converted back to its original value. |
X or x |
Hexadecimal |
Displays an integral number using the base-16 number system. |
Numeric format specifiers
Format |
Data type |
Value |
Output |
C |
Double/Int |
12345.6789 |
$12,345.68 |
E |
Double/Int |
12345.6789 |
1.234568E+004 |
E10 |
Double/Int |
12345.6789 |
1.2345678900E+004 |
e4 |
Double/Int |
12345.6789 |
1.2346e+004 |
F |
Double |
12345.6789 |
12345.68 |
F0 |
Double |
12345.6789 |
123456 |
F6 |
Double |
12345.6789 |
12345.678900 |
G |
Double |
12345.6789 |
12345.6789 |
G7 |
Double/Int |
12345.6789 |
12345.68 |
G |
Double |
0.0000023 |
2.3E-6 |
G |
Double |
0.0023 |
0.0023 |
G2 |
Double/Int |
1234 |
1.2E3 |
G |
Double/Int |
Math.PI |
3.14159265358979 |
N |
Double |
12345.6789 |
12,345.68 |
N4 |
Double |
123456789 |
123,456,789.0000 |
P |
Double/Int |
.126 |
12.60 % |
r |
Double |
Math.PI |
3.141592653589793 |
D |
Int32 |
12345 |
12345 |
D8 |
Int32 |
12345 |
00012345 |
x |
Int32 |
0x2c45e |
2c45e |
X |
Int32 |
0x2c45e |
2C45E |
X8 |
Int32 |
0x2c45e |
0002C45E |
x |
Int32 |
123456789 |
75bcd1 |
Date/time format specifiers
Format specifier |
Example |
Result |
Description |
d |
{0,1:d} |
9/29/2018 |
Displays the current day of the month, measured as a number between 1 and 31, inclusive. If the day is a single digit only (1-9), then it is displayed as a single digit. |
dd |
{0,1:dd} |
29 |
Displays the current day of the month, measured as a number between 1 and 31, inclusive. If the day is a single digit only (1-9), it is formatted with a preceding 0 (01-09). |
ddd |
{0,1:ddd} |
Fri |
Displays the abbreviated name of the day for the specified DateTime. |
dddd |
{0,1:dddd } |
Friday |
Displays the full name of the day for the specified DateTime. |
f |
{0,1:f} |
Friday, September 29, 2018 4:24 PM |
Displays seconds fractions represented in one digit. |
ff |
{0,1:ff} |
72 |
Displays seconds fractions represented in two digits. |
fff |
{0,1:fff} |
858 |
Displays seconds fractions represented in three digits. |
ffff |
{0,1:ffff} |
3393 |
Displays seconds fractions represented in four digits. |
fffff |
{0,1:fffff} |
03841 |
Displays seconds fractions represented in five digits. |
ffffff |
{0,1:ffffff} |
03841 |
Displays seconds fractions represented in six digits. |
fffffff |
{0,1:fffffff} |
6233311 |
Displays seconds fractions represented in seven digits. |
g |
{0,1:g } |
A.D. |
Displays the era (A.D. for example) for the specified DateTime. |
hh, hh |
{0,1:hh } |
04 |
Displays the hour for the specified DateTime in the range 1-12. |
HH, HH |
{0,1:HH } |
16 |
Displays the hour for the specified DateTime in the range 0-23. The hour represents whole hours passed since midnight (displayed as 0). If the hour is a single digit (0-9), it is formatted with a preceding 0 (01-09). |
m |
{0,1:m} |
September 29 |
Displays the minute for the specified DateTime in the range 0-59. The minute represents whole minutes passed since the last hour. If the minute is a single digit (0-9), it is displayed as a single digit. |
mm, mm |
{0,1:mm } |
28 |
Displays the minute for the specified DateTime in the range 0-59. The minute represents whole minutes passed since the last hour. If the minute is a single digit (0-9), it is formatted with a preceding 0 (01-09). |
M |
{0,1:M} |
September 29 |
Displays the month, measured as a number between 1 and 12, inclusive. If the month is a single digit (1-9), it is displayed as a single digit. |
MM |
{0,1:MM} |
09 |
Displays the month, measured as a number between 1 and 12, inclusive. If the month is a single digit (1-9), it is formatted with a preceding 0 (01-09). |
MMM |
{0,1:MMM} |
Sep |
Displays the abbreviated name of the month for the specified DateTime. |
MMMM |
{0,1:MMMM} |
September |
Displays the full name of the month for the specified DateTime. |
s |
{0,1:s} |
2018-09-29T16:30:26 |
Displays the seconds for the specified DateTime in the range 0-59. The second represents whole seconds passed since the last minute. If the second is a single digit (0-9), it is displayed as a single digit only. |
ss, ss |
{0,1:ss} |
13 |
Displays the seconds for the specified DateTime in the range 0-59. The second represents whole seconds passed since the last minute. If the second is a single digit (0-9), it is formatted with a preceding 0 (01-09). |
t |
{0,1:t} |
4:31 PM |
Displays the first character of the A.M./P.M. designator for the specified DateTime. |
tt |
{0,1:tt} |
PM |
Displays the A.M./P.M. designator for the specified DateTime. |
y |
{0,1:y} |
September, 2018 |
Displays the year for the specified DateTime as a maximum two-digit number. The first two digits of the year are omitted. If the year is a single digit (1-9), it is displayed as a single digit. |
yy |
{0,1:yy} |
06 |
Displays the year for the specified DateTime as a maximum two-digit number. The first two digits of the year are omitted. If the year is a single digit (1-9), it is formatted with a preceding 0 (01-09). |
yyyy |
{0,1:yyyy} |
2018 |
Displays the year for the specified DateTime, including the century. If the year is less than four digits in length, then preceding zeros are appended as necessary to make the displayed year four digits long. |
zz |
{0,1:zz} |
-04 |
Displays the time zone offset for the system's current time zone in whole hours only. The offset is displayed with a leading or trailing sign (zero is displayed as "+00"), indicating hours ahead of Greenwich mean time (+) or hours behind Greenwich mean time (-). The range of values is –12 to +13. If the offset is a single digit (0-9), it is formatted with a preceding 0 (01-09) with the appropriate leading sign. The setting for the time zone is specified as +X or –X where X is the offset in hours from GMT. The displayed offset is affected by daylight savings time. |
zzz, zzz |
{0,1:zzz} |
-04:00 |
Displays the time zone offset for the system's current time zone in hours and minutes. The offset is displayed with a leading or trailing sign (zero is displayed as "+00:00"), indicating hours ahead of Greenwich mean time (+) or hours behind Greenwich mean time (-). The range of values is –12:00 to +13:00. If the offset is a single digit (0-9), it is formatted with a preceding 0 (01-09) with the appropriate leading sign. The setting for the time zone is specified as +X or –X where X is the offset in hours from GMT. The displayed offset is affected by daylight savings time. |
: |
{0,1:hh:mm} |
04:34 |
Time separator. |
/ |
{0,1: MM/dd} |
09/29 |
Date separator. |
Privacy | Trademarks | Terms of Use | Feedback
Updated: 18 June 2020
© 2016 - 2020 Pegasystems Inc. Cambridge, MA All rights reserved.