Number Formatting
Use a large selection of different number formatting properties to add data to
your documents.
View on YouTube
int Literals
To show an integer, simply include the literal number as one of the elements inside a span.
IntegerLiteral
=
Span
{
42
;
};
42
Functions and Variables with int Values
Functions that return integers or variables containing integers, like the function X shown here, will
be formatted the same way.
X
(
i
)
=
i
*
i
+
3;
IntegerVariable
=
Span
{
"The output of X(5) is "
;
X
(5);
};
The output of X(5) is 28
Hexadecimal Format
To format an integer in hexadecimal, change the
TextRadix
to 16.
IntegerHexadecimal
=
Span
{
TextRadix
:
16
;
129579;
};
1fa2b
Uppercase Hex Format
To have the hex digits shown in upper-case, change the
TextCase
property to AllUpper.
IntegerHexadecimalUpper
=
Span
{
TextRadix
:
16;
TextCase
:
AllUpper
;
671277;
};
A3E2D
Binary Format
To format a number in binary, use 2 as the
TextRadix
.
IntegerBinary
=
Span
{
TextRadix
:
2
;
127;
};
1111111
Number Zero-Padding
Use the
TextNumPadding
property to set the minimum width of a number. This is handy for text
sorting and creating tables with aligned numbers.
IntegerHexadecimal4
=
Block
{
TextRadix
:
16;
TextNumPadding
:
4
;
4;
27;
12245;
};
0004
001b
2fd5
Group Separators
To format an integer with a group separator, set the
TextGroup
property to true.
IntegerGroup
=
Span
{
TextGroup
:
true
;
1234567.89;
};
1,234,567.89
Culture Settings
Use the
TextCulture
property to ensure the formatting is correct for the intended readership.
IntegerGroupCulture
=
Span
{
TextCulture
:
CultureInfo
.
FindCulture
(
"de-DE"
);
TextGroup
:
true
;
8912345.67;
};
8.912.345,67
double Literals
As with integers, to a format a number of type
double
, include it as an element in the revision.
DoubleFormatting
=
Span
{
4325.1245
;
};
4325.1245
Function Return Values
Formatting a return value from a function works the same way.
DoubleReturn
=
Span
{
Math
.
Sqrt
(1
+
1)
;
};
1.4142135623730951
Decimal Digits
Use the
TextDigits
property to fix the number of fractional digits in the number.
DoubleDigits
=
Span
{
TextDigits
:
3
;
Math
.
PI
;
};
3.142
Percentage Format
Set the
TextPercent
property to true to show numbers as percentages.
Percentage
=
Block
{
TextPercent
:
true
;
0.04;
1.5;
};
4%
150%
Significant Figures
Set
TextSignificant
to true, to make TextDigits refer to 'significant' figures, rather than decimal
digits.
SignificantDigits
=
Block
{
TextSignificant
:
true
;
TextDigits
:
3
;
// 3 significant figures
4325.1245;
5.4193;
0.0006427;
1.215e10;
1.2e-10;
};
4330
5.42
0.000643
12200000000
0.000000000120
Scientific Notation
Format the number in scientific notation by setting
TextScientific
to true.
ScientificNotation
=
Span
{
TextScientific
:
true
;
TextDigits
:
2;
175_000;
};
1.75x10
5
Significant Figures in Scientific Notation
Notice that the
TextSignificant
property controls the total number of significant figures with
scientific notation.
ScientificNotationSig
=
Span
{
TextScientific
:
true
;
TextSignificant
:
true
;
TextDigits
:
2
;
8_175_400;
};
8.2x10
6
Decimal Tab Stops
You can use a custom tab stop in a paragraph to align numbers on decimal point.
readonly
AlignedPar
=
Paragraph
(
null
, [
new
(5%,
Decimal
)]);
AlignedPars
=
Block
{
AlignedPar
{
Tab
; 1.2 };
AlignedPar
{
Tab
; 123.99};
AlignedPar
{
Tab
; 0.5544};
};
1.2
123.99
0.5544
Fractional Expressions
Use the
TextDenominator
property to convert a number to a fraction, with a maximum
denominator, in lowest terms.
Denominator
=
Block
{
TextDenominator
:
16
;
0.125;
0.5;
12.75;
1.04125;
};
1
8
1
2
12
3
4
1
1
16