Skip to content

Implement remaining string format codes for floats #1656

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

Closed
6 tasks done
doyshinda opened this issue Jan 2, 2020 · 3 comments
Closed
6 tasks done

Implement remaining string format codes for floats #1656

doyshinda opened this issue Jan 2, 2020 · 3 comments
Labels
A-stdlib C-compat A discrepancy between RustPython and CPython good first issue Good for newcomers

Comments

@doyshinda
Copy link
Contributor

doyshinda commented Jan 2, 2020

Feature

Implement the g, G, e, E, n, and % format codes for floats.

  • g
  • G
  • e
  • E
  • n
  • %

A few examples from CPython:

>>> '{:g}'.format(10.0)
'10'
>>> '{:.1g}'.format(10.0)
'1e+01'
>>> '{:e}'.format(10.0)
'1.000000e+01'
>>> '{:.1e}'.format(10.0)
'1.0e+01'
>>> '{:n}'.format(999999.1234)
'999999'
>>> '{:n}'.format(1000000.1234)
'1e+06'
>>> '{:.8n}'.format(1000000.1234)
'1000000.1'
>>> '{:.11n}'.format(1000000.1234)
'1000000.1234'
>>> '{:%}'.format(10.0)
'1000.000000%'

RustPython

>>>>> '{:g}'.format(10.0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Format code 'g' for object of type 'float' not implemented yet
>>>>> '{:G}'.format(10.0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Format code 'G' for object of type 'float' not implemented yet
>>>>> '{:e}'.format(10.0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Format code 'e' for object of type 'float' not implemented yet
>>>>> '{:E}'.format(10.0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Format code 'E' for object of type 'float' not implemented yet
>>>>> '{:n}'.format(10.0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Format code 'n' for object of type 'float' not implemented yet
>>>>> '{:%}'.format(10.0)
'10.0'

Python Documentation

See the section after The available presentation types for floating point and decimal values are in the docs found here.

@doyshinda doyshinda added the C-compat A discrepancy between RustPython and CPython label Jan 2, 2020
doyshinda added a commit to doyshinda/RustPython that referenced this issue Jan 3, 2020
doyshinda added a commit to doyshinda/RustPython that referenced this issue Jan 3, 2020
doyshinda added a commit to doyshinda/RustPython that referenced this issue Jan 3, 2020
@merkrafter
Copy link
Contributor

merkrafter commented Jan 31, 2021

Please update the current status of this issue.
It looks like e.g. :g and :G are supported meanwhile (though not yielding the same results as CPython does in every case in the master branch as of writing this (which is now addressed in #2431 )).

@DimitrisJim DimitrisJim added the good first issue Good for newcomers label Jan 1, 2023
@youknowone youknowone added good first issue Good for newcomers and removed good first issue Good for newcomers labels Feb 22, 2023
@JazzGlobal
Copy link
Contributor

Im gonna go ahead and wrap up the 'n' case.

@DimitrisJim
Copy link
Member

Thanks all who contributed, closing issue now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-stdlib C-compat A discrepancy between RustPython and CPython good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

5 participants