Skip to content
This repository was archived by the owner on Mar 1, 2024. It is now read-only.

Support python style f"{x:0.2}" #41

Open
innerlee opened this issue Aug 4, 2017 · 2 comments
Open

Support python style f"{x:0.2}" #41

innerlee opened this issue Aug 4, 2017 · 2 comments

Comments

@innerlee
Copy link

innerlee commented Aug 4, 2017

In python, the following style is convenient:

>>> x = 1.234
>>> f"{x:0.2}"
'1.23'

It would be great if we

  • can write variable inside brackets
  • support string prefix f"some string with formats" to do this formatting
@ScottPJones
Copy link
Collaborator

A type of f"some string with formats" is already supported in the StringLiterals package. The syntax isn't quite the same as the Python syntax, that is something that I'd like to make closer, if possible.
I tried your example, however, it needed to be changed to work as you showed:
f"{x:0.2f}" returns '1.23', but f"{x:0.2}" returns '1.2'
Currently, for StringLiterals, you need to have f"\{0.2f}(x), as stated in the README, I'd like to make that closer to the Python syntax, so that the only difference would be the leading backslash (which is important to keep formatting operations from interfering with normal string syntax).

@ludwigwinkler
Copy link

Hi,

any update on the f-string style formatting?

Thanks for your effort!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants