Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation for '%' format type. #1071

Merged
merged 2 commits into from
Mar 6, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion doc/syntax.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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'``. |
+---------+----------------------------------------------------------+

Expand Down Expand Up @@ -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::
Copy link
Contributor

@vitaut vitaut Mar 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably need a newline after '::'.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

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);
Expand Down Expand Up @@ -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