Add support for string formatting of floats with ":f" format code#1651
Conversation
|
Contributes to #1613 |
4bd71d7 to
64ff6e8
Compare
f4334db to
a54d015
Compare
coolreader18
left a comment
There was a problem hiding this comment.
This looks good, thanks for working on this!
| let mut remaining: usize = magnitude_string.len(); | ||
| for c in magnitude_string.chars() { | ||
|
|
||
| // Don't add separators to the floating decimal point of numbers |
There was a problem hiding this comment.
I'm not sure exactly what the functionality of this is supposed to be, but you might want to do .splitn('.', 2) so that the splitting sort of has right associativity. Then you don't have to .collect() it and you can do let magnitude_integer_string = parts.next().unwrap(); and if let Some(part) = parts.next() { ... }
There was a problem hiding this comment.
This is needed to prevent adding an incorrect separator to floats, as this is what it looked like before:
>>>>> '{:,.2f}'.format(1234567890.1234)
'1,234,567,890,.12'With this change, it's only adding the separator to the integer portion of the number:
>>>>> '{:,.2f}'.format(1234567890.1234)
'1,234,567,890.12'I'll change it to the way you suggested, as that is cleaner.
Also adds automatic conversion of int -> float when the ":f" format code is specified. Fixes a f-string formatting style regression introduced in RustPython#1625.
a54d015 to
30473d3
Compare
|
Thanks for contributing! |
Also adds automatic conversion of int -> float when the ":f"
format code is specified.