Formatting.jl icon indicating copy to clipboard operation
Formatting.jl copied to clipboard

Support python style f"{x:0.2}"

Open innerlee opened this issue 8 years ago • 2 comments

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

innerlee avatar Aug 04 '17 07:08 innerlee

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).

ScottPJones avatar Apr 10 '18 13:04 ScottPJones

Hi,

any update on the f-string style formatting?

Thanks for your effort!

ludwigwinkler avatar Nov 06 '19 08:11 ludwigwinkler