From 0e3e0295804925d9dd6b503d884c896f77b5d680 Mon Sep 17 00:00:00 2001 From: gawain Date: Wed, 6 Mar 2019 21:01:45 +0100 Subject: [PATCH 1/2] Add documentation for '%' format type. --- doc/syntax.rst | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/doc/syntax.rst b/doc/syntax.rst index fc27c5e2933f..20cf6dd61025 100644 --- a/doc/syntax.rst +++ b/doc/syntax.rst @@ -264,6 +264,10 @@ The available presentation types for floating-point values are: | | ``'E'`` if the number gets too large. The | | | representations of infinity and NaN are uppercased, too. | +---------+----------------------------------------------------------+ +| ``'%'`` | Fixed point as a percentage. This is similar to ``'f'``, | +| | but the argument is multiplied by 100 and a percent sign | +| | ``%`` is appended. | ++---------+----------------------------------------------------------+ | none | The same as ``'g'``. | +---------+----------------------------------------------------------+ @@ -357,6 +361,12 @@ Replacing ``%+f``, ``%-f``, and ``% f`` and specifying a sign:: format("{:-f}; {:-f}", 3.14, -3.14); // show only the minus -- same as '{:f}; {:f}' // Result: "3.140000; -3.140000" +As a percentage:: + format("{0:f} or {0:%}", .635); + // Result: "0.635000 or 63.500000%" + format("{:*^{}.{}%}", 1., 15, 2); // With fill, dynamic width and dynamic precision. + // Result: "****100.00%****" + Replacing ``%x`` and ``%o`` and converting the value to different bases:: format("int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42); @@ -412,4 +422,3 @@ Padded hex byte with prefix and always prints both hex characters:: 9 9 11 1001 10 A 12 1010 11 B 13 1011 - From f812f293a13db1d6c4bb04447593e947d6cd108c Mon Sep 17 00:00:00 2001 From: gawain Date: Wed, 6 Mar 2019 22:00:20 +0100 Subject: [PATCH 2/2] Add newline as requested. --- doc/syntax.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/syntax.rst b/doc/syntax.rst index 20cf6dd61025..914ef34af488 100644 --- a/doc/syntax.rst +++ b/doc/syntax.rst @@ -362,6 +362,7 @@ Replacing ``%+f``, ``%-f``, and ``% f`` and specifying a sign:: // Result: "3.140000; -3.140000" As a percentage:: + format("{0:f} or {0:%}", .635); // Result: "0.635000 or 63.500000%" format("{:*^{}.{}%}", 1., 15, 2); // With fill, dynamic width and dynamic precision.