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

Trailing dot is returned for formatFloat with precision 0 #12586

Closed
GULPF opened this issue Nov 3, 2019 · 2 comments
Closed

Trailing dot is returned for formatFloat with precision 0 #12586

GULPF opened this issue Nov 3, 2019 · 2 comments

Comments

@GULPF
Copy link
Member

GULPF commented Nov 3, 2019

strututils.formatFloat returns a trailing dot when using precision = 0.

Example

import strutils
echo formatFloat(2.123, ffDecimal, precision = 0)

Current Output

2.

Expected Output

2

Additional Information

With the JS backend the expected result is returned. Tested with latest devel.

@mratsim
Copy link
Collaborator

mratsim commented Nov 3, 2019

I don't really mind the trailing dot, it actually reminds me that I'm using floats.
It seems like Python does remove it as well though and AFAIK we want to be Python-like for formatting.

a = 3.14159

print(f'{a:.0f}')
print('%.0f' % a)
print("{0:.0f}".format(a))

@juancarlospaco
Copy link
Collaborator

juancarlospaco commented Nov 3, 2019

Maybe you want to format a float for SASS/SCSS for example.

narimiran added a commit to narimiran/Nim that referenced this issue Nov 4, 2019
…ion = 0'

'formatFloat' with 'precision = 0' now gives the same result
(a number without a decimal point) in all backends.
This is compatible with Python's formatters, too.
narimiran added a commit to narimiran/Nim that referenced this issue Nov 5, 2019
…ion = 0'

'formatFloat' with 'precision = 0' now gives the same result
(a number without a decimal point) in all backends.
This is compatible with Python's formatters, too.
@Araq Araq closed this as completed in ffa9a74 Nov 5, 2019
kiyolee pushed a commit to kiyolee/nim that referenced this issue Nov 7, 2019
…ion = 0' (nim-lang#12592)

* fix nim-lang#8242, fix nim-lang#12586: fix 'formatFloat' with 'precision = 0'

'formatFloat' with 'precision = 0' now gives the same result
(a number without a decimal point) in all backends.
This is compatible with Python's formatters, too.

* fix failing tests

* add changelog entry

* add version switch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants