Skip to content

Add section for formatting digits #92

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

Merged
merged 3 commits into from
Jul 31, 2022

Conversation

flymemoryRPA
Copy link
Contributor

Adding thousands separator
Rounding
Showing as Percentage

Adding thousands separator
Rounding
Showing as Percentage
@netlify
Copy link

netlify bot commented Jul 30, 2022

‼️ Deploy request for pythoncheatsheet rejected.

Name Link
🔨 Latest commit ab9fdc6

@wilfredinni
Copy link
Owner

In the example for Adding thousands separator, you forgot to add the "...":

>>> a = 10000000
>>> print({0:,}.format(a))
  File "<stdin>", line 1
    print({0:,}.format(a))
             ^
SyntaxError: invalid syntax

It should be:

>>> a = 10000000
>>> print("{0:,}".format(a))
10,000,000

Also, try to avoid using print as much as possible. Since most of the examples come from the interpreter itself, it is enough to just use the variable or expression:

>>> # Adding thousands separator
>>> n = 10000000
>>> "{0:,}".format(a)
'10,000,000'

>>> # Rounding
>>> n = 3.1415926
>>> "{0:.2f}".format(n)
'3.14'

>>> # Showing as Percentage
>>> n = 0.816562
>>> "{0:.2%}".format(n)
'81.66%'

This is a great addition, so I will wait for you to fix this and then merge to production 🤩

@flymemoryRPA
Copy link
Contributor Author

Thank you for the comments. Have made the edits.

@wilfredinni wilfredinni merged commit 9e309fa into wilfredinni:master Jul 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants