From c1a390bee918f045272c46cbf166070544ed4419 Mon Sep 17 00:00:00 2001 From: Christopher Gambrell Date: Fri, 7 Apr 2023 16:41:55 -0400 Subject: [PATCH 01/12] N and n support for float format. --- common/src/float_ops.rs | 23 +++++++++++++++++++++++ common/src/format.rs | 21 +++++++++++++-------- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/common/src/float_ops.rs b/common/src/float_ops.rs index cd15c2106f..868e20e26a 100644 --- a/common/src/float_ops.rs +++ b/common/src/float_ops.rs @@ -235,6 +235,29 @@ pub fn format_general( } } +pub fn format_number(magnitude: f64, precision: usize) -> String { + let magnitude_as_string = magnitude.to_string(); + let separator_index = magnitude_as_string.chars().position(|c| c == '.').unwrap(); + if separator_index == precision { return String::from(&magnitude_as_string[..separator_index]) } + if separator_index < precision + { + let prefix = &magnitude_as_string[0..separator_index]; + let suffix_distance = (precision - prefix.len() + 1) + separator_index; + let suffix = &magnitude_as_string[separator_index..suffix_distance]; + + return format!("{}{}", prefix, suffix) + } + format!("{}e+0{}", &magnitude_as_string[..1], get_num_of_char(&magnitude_as_string, '0')) +} + +fn get_num_of_char(text: &String, value: char) -> i32 { + let mut total = 0; + for char in text.chars() { + if char == value { total += 1 } + } + total +} + pub fn to_string(value: f64) -> String { let lit = format!("{value:e}"); if let Some(position) = lit.find('e') { diff --git a/common/src/format.rs b/common/src/format.rs index 62c703c85f..6196943b6c 100644 --- a/common/src/format.rs +++ b/common/src/format.rs @@ -126,7 +126,7 @@ pub enum FormatType { Character, Decimal, Octal, - Number, + Number(Case), Hex(Case), Exponent(Case), GeneralFormat(Case), @@ -142,7 +142,8 @@ impl From<&FormatType> for char { FormatType::Character => 'c', FormatType::Decimal => 'd', FormatType::Octal => 'o', - FormatType::Number => 'n', + FormatType::Number(Case::Lower) => 'n', + FormatType::Number(Case::Upper) => 'N', FormatType::Hex(Case::Lower) => 'x', FormatType::Hex(Case::Upper) => 'X', FormatType::Exponent(Case::Lower) => 'e', @@ -165,7 +166,8 @@ impl FormatParse for FormatType { Some('c') => (Some(Self::Character), chars.as_str()), Some('d') => (Some(Self::Decimal), chars.as_str()), Some('o') => (Some(Self::Octal), chars.as_str()), - Some('n') => (Some(Self::Number), chars.as_str()), + Some('n') => (Some(Self::Number(Case::Lower)), chars.as_str()), + Some('N') => (Some(Self::Number(Case::Upper)), chars.as_str()), Some('x') => (Some(Self::Hex(Case::Lower)), chars.as_str()), Some('X') => (Some(Self::Hex(Case::Upper)), chars.as_str()), Some('e') => (Some(Self::Exponent(Case::Lower)), chars.as_str()), @@ -367,14 +369,14 @@ impl FormatSpec { | FormatType::Binary | FormatType::Octal | FormatType::Hex(_) - | FormatType::Number, + | FormatType::Number(_), ) => { let ch = char::from(format_type); Err(FormatSpecError::UnspecifiedFormat(',', ch)) } ( Some(FormatGrouping::Underscore), - FormatType::String | FormatType::Character | FormatType::Number, + FormatType::String | FormatType::Character | FormatType::Number(_), ) => { let ch = char::from(format_type); Err(FormatSpecError::UnspecifiedFormat('_', ch)) @@ -386,7 +388,7 @@ impl FormatSpec { fn get_separator_interval(&self) -> usize { match self.format_type { Some(FormatType::Binary | FormatType::Octal | FormatType::Hex(_)) => 4, - Some(FormatType::Decimal | FormatType::Number | FormatType::FixedPoint(_)) => 3, + Some(FormatType::Decimal | FormatType::Number(_) | FormatType::FixedPoint(_)) => 3, None => 3, _ => panic!("Separators only valid for numbers!"), } @@ -434,7 +436,10 @@ impl FormatSpec { let ch = char::from(self.format_type.as_ref().unwrap()); Err(FormatSpecError::UnknownFormatCode(ch, "float")) } - Some(FormatType::Number) => Err(FormatSpecError::NotImplemented('n', "float")), + Some(FormatType::Number(_)) => { + let precision = if precision == 0 { 6 } else { precision }; + Ok(float_ops::format_number(magnitude, precision)) + }, Some(FormatType::GeneralFormat(case)) => { let precision = if precision == 0 { 1 } else { precision }; Ok(float_ops::format_general( @@ -531,7 +536,7 @@ impl FormatSpec { Ok(result) } }, - Some(FormatType::Number) => self.format_int_radix(magnitude, 10), + Some(FormatType::Number(_)) => self.format_int_radix(magnitude, 10), Some(FormatType::String) => Err(FormatSpecError::UnknownFormatCode('s', "int")), Some(FormatType::Character) => match (self.sign, self.alternate_form) { (Some(_), _) => Err(FormatSpecError::NotAllowed("Sign")), From 03a89901fa99c5cf38c0a400fced45147a90cf63 Mon Sep 17 00:00:00 2001 From: Christopher Gambrell Date: Fri, 7 Apr 2023 22:31:53 -0400 Subject: [PATCH 02/12] Satisfy github actions --- common/src/float_ops.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/float_ops.rs b/common/src/float_ops.rs index 868e20e26a..cf1406b9c2 100644 --- a/common/src/float_ops.rs +++ b/common/src/float_ops.rs @@ -250,7 +250,7 @@ pub fn format_number(magnitude: f64, precision: usize) -> String { format!("{}e+0{}", &magnitude_as_string[..1], get_num_of_char(&magnitude_as_string, '0')) } -fn get_num_of_char(text: &String, value: char) -> i32 { +fn get_num_of_char(text: &str, value: char) -> i32 { let mut total = 0; for char in text.chars() { if char == value { total += 1 } From a937e8eefe42f0fdd32776a18d550fa5adf7c03f Mon Sep 17 00:00:00 2001 From: Christopher Gambrell Date: Fri, 7 Apr 2023 23:25:25 -0400 Subject: [PATCH 03/12] cargo fmt --- common/src/float_ops.rs | 21 ++++++++++++++------- common/src/format.rs | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/common/src/float_ops.rs b/common/src/float_ops.rs index cf1406b9c2..39e4564534 100644 --- a/common/src/float_ops.rs +++ b/common/src/float_ops.rs @@ -238,22 +238,29 @@ pub fn format_general( pub fn format_number(magnitude: f64, precision: usize) -> String { let magnitude_as_string = magnitude.to_string(); let separator_index = magnitude_as_string.chars().position(|c| c == '.').unwrap(); - if separator_index == precision { return String::from(&magnitude_as_string[..separator_index]) } - if separator_index < precision - { + if separator_index == precision { + return String::from(&magnitude_as_string[..separator_index]); + } + if separator_index < precision { let prefix = &magnitude_as_string[0..separator_index]; let suffix_distance = (precision - prefix.len() + 1) + separator_index; - let suffix = &magnitude_as_string[separator_index..suffix_distance]; + let suffix = &magnitude_as_string[separator_index..suffix_distance]; - return format!("{}{}", prefix, suffix) + return format!("{}{}", prefix, suffix); } - format!("{}e+0{}", &magnitude_as_string[..1], get_num_of_char(&magnitude_as_string, '0')) + format!( + "{}e+0{}", + &magnitude_as_string[..1], + get_num_of_char(&magnitude_as_string, '0') + ) } fn get_num_of_char(text: &str, value: char) -> i32 { let mut total = 0; for char in text.chars() { - if char == value { total += 1 } + if char == value { + total += 1 + } } total } diff --git a/common/src/format.rs b/common/src/format.rs index 6196943b6c..2beccdcc20 100644 --- a/common/src/format.rs +++ b/common/src/format.rs @@ -439,7 +439,7 @@ impl FormatSpec { Some(FormatType::Number(_)) => { let precision = if precision == 0 { 6 } else { precision }; Ok(float_ops::format_number(magnitude, precision)) - }, + } Some(FormatType::GeneralFormat(case)) => { let precision = if precision == 0 { 1 } else { precision }; Ok(float_ops::format_general( From 9627142fa133f43e23fb54b723e922d66c0a3d87 Mon Sep 17 00:00:00 2001 From: Christopher Gambrell Date: Fri, 7 Apr 2023 23:51:37 -0400 Subject: [PATCH 04/12] Added tests --- extra_tests/snippets/builtin_str.py | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/extra_tests/snippets/builtin_str.py b/extra_tests/snippets/builtin_str.py index 8adf97b731..5c4e87c44a 100644 --- a/extra_tests/snippets/builtin_str.py +++ b/extra_tests/snippets/builtin_str.py @@ -611,6 +611,45 @@ def try_mutate_str(): assert '{:g}'.format(1.020e-13) == '1.02e-13' assert "{:g}".format(1.020e-4) == '0.000102' +# Test n & N formatting +assert '{:n}'.format(999999.1234) == '999999' +assert '{:n}'.format(9999.1234) == '9999.12' +assert '{:n}'.format(-1000000.1234) == '-1e+06' +assert '{:n}'.format(1000000.1234) == '1e+06' +assert '{:.1n}'.format(1000000.1234) == '1e+06' +assert '{:.2n}'.format(1000000.1234) == '1e+06' +assert '{:.3n}'.format(1000000.1234) == '1e+06' +assert '{:.4n}'.format(1000000.1234) == '1e+06' +assert '{:.5n}'.format(1000000.1234) == '1e+06' +assert '{:.6n}'.format(1000000.1234) == '1e+06' +assert '{:.7n}'.format(1000000.1234) == '1000000' +assert '{:.8n}'.format(1000000.1234) == '1000000.1' +assert '{:.10n}'.format(1000000.1234) == '1000000.123' +assert '{:.11n}'.format(1000000.1234) == '1000000.1234' +assert '{:.11n}'.format(-1000000.1234) == '-1000000.1234' +assert '{:0n}'.format(-1000000.1234) == '-1e+06' +assert '{:n}'.format(-1000000.1234) == '-1e+06' +assert '{:-1n}'.format(-1000000.1234) == '-1e+06' + +assert '{:N}'.format(999999.1234) == '999999' +assert '{:N}'.format(9999.1234) == '9999.12' +assert '{:N}'.format(-1000000.1234) == '-1e+06' +assert '{:N}'.format(1000000.1234) == '1e+06' +assert '{:.1N}'.format(1000000.1234) == '1e+06' +assert '{:.2N}'.format(1000000.1234) == '1e+06' +assert '{:.3N}'.format(1000000.1234) == '1e+06' +assert '{:.4N}'.format(1000000.1234) == '1e+06' +assert '{:.5N}'.format(1000000.1234) == '1e+06' +assert '{:.6N}'.format(1000000.1234) == '1e+06' +assert '{:.7N}'.format(1000000.1234) == '1000000' +assert '{:.8N}'.format(1000000.1234) == '1000000.1' +assert '{:.10N}'.format(1000000.1234) == '1000000.123' +assert '{:.11N}'.format(1000000.1234) == '1000000.1234' +assert '{:.11N}'.format(-1000000.1234) == '-1000000.1234' +assert '{:0N}'.format(-1000000.1234) == '-1e+06' +assert '{:N}'.format(-1000000.1234) == '-1e+06' +assert '{:-1N}'.format(-1000000.1234) == '-1e+06' + # remove*fix test def test_removeprefix(): s = 'foobarfoo' From d8c3f1167c8cbd445a1f6630a15456cf182cdbc1 Mon Sep 17 00:00:00 2001 From: Christopher Gambrell Date: Sat, 8 Apr 2023 23:29:29 -0400 Subject: [PATCH 05/12] Fixed tests and N case functionality --- common/src/format.rs | 5 +++-- extra_tests/snippets/builtin_str.py | 26 ++++++++------------------ 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/common/src/format.rs b/common/src/format.rs index 2beccdcc20..51f69761d2 100644 --- a/common/src/format.rs +++ b/common/src/format.rs @@ -432,11 +432,12 @@ impl FormatSpec { | Some(FormatType::Octal) | Some(FormatType::Hex(_)) | Some(FormatType::String) - | Some(FormatType::Character) => { + | Some(FormatType::Character) + | Some(FormatType::Number(Case::Upper)) => { let ch = char::from(self.format_type.as_ref().unwrap()); Err(FormatSpecError::UnknownFormatCode(ch, "float")) } - Some(FormatType::Number(_)) => { + Some(FormatType::Number(Case::Lower)) => { let precision = if precision == 0 { 6 } else { precision }; Ok(float_ops::format_number(magnitude, precision)) } diff --git a/extra_tests/snippets/builtin_str.py b/extra_tests/snippets/builtin_str.py index 5c4e87c44a..cd7133e355 100644 --- a/extra_tests/snippets/builtin_str.py +++ b/extra_tests/snippets/builtin_str.py @@ -631,24 +631,14 @@ def try_mutate_str(): assert '{:n}'.format(-1000000.1234) == '-1e+06' assert '{:-1n}'.format(-1000000.1234) == '-1e+06' -assert '{:N}'.format(999999.1234) == '999999' -assert '{:N}'.format(9999.1234) == '9999.12' -assert '{:N}'.format(-1000000.1234) == '-1e+06' -assert '{:N}'.format(1000000.1234) == '1e+06' -assert '{:.1N}'.format(1000000.1234) == '1e+06' -assert '{:.2N}'.format(1000000.1234) == '1e+06' -assert '{:.3N}'.format(1000000.1234) == '1e+06' -assert '{:.4N}'.format(1000000.1234) == '1e+06' -assert '{:.5N}'.format(1000000.1234) == '1e+06' -assert '{:.6N}'.format(1000000.1234) == '1e+06' -assert '{:.7N}'.format(1000000.1234) == '1000000' -assert '{:.8N}'.format(1000000.1234) == '1000000.1' -assert '{:.10N}'.format(1000000.1234) == '1000000.123' -assert '{:.11N}'.format(1000000.1234) == '1000000.1234' -assert '{:.11N}'.format(-1000000.1234) == '-1000000.1234' -assert '{:0N}'.format(-1000000.1234) == '-1e+06' -assert '{:N}'.format(-1000000.1234) == '-1e+06' -assert '{:-1N}'.format(-1000000.1234) == '-1e+06' +with AssertRaises(ValueError, msg="Unknown format code 'N' for object of type 'float'"): + '{:N}'.format(999999.1234) +with AssertRaises(ValueError, msg="Unknown format code 'N' for object of type 'float'"): + '{:.1N}'.format(1000000.1234) +with AssertRaises(ValueError, msg="Unknown format code 'N' for object of type 'float'"): + '{:0N}'.format(-1000000.1234) +with AssertRaises(ValueError, msg="Unknown format code 'N' for object of type 'float'"): + '{:-1N}'.format(-1000000.1234) # remove*fix test def test_removeprefix(): From f17f7a4bdf57e135fca12b40e00bbb2f2974cc89 Mon Sep 17 00:00:00 2001 From: Christopher Gambrell Date: Sun, 9 Apr 2023 12:15:44 -0400 Subject: [PATCH 06/12] Fixed possibility of precision being larger than magnitude. --- Lib/test/test_enum.py | 2 -- common/src/format.rs | 4 +++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py index 0c640c2536..053c7bff22 100644 --- a/Lib/test/test_enum.py +++ b/Lib/test/test_enum.py @@ -529,8 +529,6 @@ def test_format_enum_date(self): self.assertFormatIsValue('{:%Y %m}', Holiday.IDES_OF_MARCH) self.assertFormatIsValue('{:%Y %m %M:00}', Holiday.IDES_OF_MARCH) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_format_enum_float(self): Konstants = self.Konstants self.assertFormatIsValue('{}', Konstants.TAU) diff --git a/common/src/format.rs b/common/src/format.rs index 51f69761d2..6dbdba2330 100644 --- a/common/src/format.rs +++ b/common/src/format.rs @@ -438,7 +438,9 @@ impl FormatSpec { Err(FormatSpecError::UnknownFormatCode(ch, "float")) } Some(FormatType::Number(Case::Lower)) => { - let precision = if precision == 0 { 6 } else { precision }; + let size = magnitude.to_string().replace(".", "").len(); + // If we get a precision larger than the magnitude (without the decimal), use the size. + let precision = if precision > size { size } else { precision }; Ok(float_ops::format_number(magnitude, precision)) } Some(FormatType::GeneralFormat(case)) => { From e5fd98d2f9cae7537b1e762d3354c0792a4e5308 Mon Sep 17 00:00:00 2001 From: Christopher Gambrell Date: Sun, 9 Apr 2023 13:14:58 -0400 Subject: [PATCH 07/12] Lint error. --- common/src/format.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/format.rs b/common/src/format.rs index 6dbdba2330..d29f0838be 100644 --- a/common/src/format.rs +++ b/common/src/format.rs @@ -438,7 +438,7 @@ impl FormatSpec { Err(FormatSpecError::UnknownFormatCode(ch, "float")) } Some(FormatType::Number(Case::Lower)) => { - let size = magnitude.to_string().replace(".", "").len(); + let size = magnitude.to_string().replace('.', '').len(); // If we get a precision larger than the magnitude (without the decimal), use the size. let precision = if precision > size { size } else { precision }; Ok(float_ops::format_number(magnitude, precision)) From d08a36edde6bf9e5815c4e9f80a318a759b9c747 Mon Sep 17 00:00:00 2001 From: Christopher Gambrell Date: Sun, 9 Apr 2023 20:19:22 -0400 Subject: [PATCH 08/12] Lint Error Part 2. --- common/src/format.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/format.rs b/common/src/format.rs index d29f0838be..71a8957184 100644 --- a/common/src/format.rs +++ b/common/src/format.rs @@ -438,7 +438,7 @@ impl FormatSpec { Err(FormatSpecError::UnknownFormatCode(ch, "float")) } Some(FormatType::Number(Case::Lower)) => { - let size = magnitude.to_string().replace('.', '').len(); + let size = magnitude.to_string().replace('.', "").len(); // If we get a precision larger than the magnitude (without the decimal), use the size. let precision = if precision > size { size } else { precision }; Ok(float_ops::format_number(magnitude, precision)) From f46e88fa77987c51158048958f923c1e0096ef19 Mon Sep 17 00:00:00 2001 From: Christopher Gambrell Date: Mon, 10 Apr 2023 08:22:11 -0400 Subject: [PATCH 09/12] Unmark as expected fail. --- Lib/test/test_format.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/Lib/test/test_format.py b/Lib/test/test_format.py index b95f592c7b..f6c11a4aad 100644 --- a/Lib/test/test_format.py +++ b/Lib/test/test_format.py @@ -420,8 +420,6 @@ def test_non_ascii(self): self.assertEqual(format(1+2j, "\u2007^8"), "\u2007(1+2j)\u2007") self.assertEqual(format(0j, "\u2007^4"), "\u20070j\u2007") - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_locale(self): try: oldloc = locale.setlocale(locale.LC_ALL) From a6e7a55453a046726c951e5d29d8a5e6afecad27 Mon Sep 17 00:00:00 2001 From: Christopher Gambrell Date: Mon, 10 Apr 2023 08:59:41 -0400 Subject: [PATCH 10/12] Fixed tests --- common/src/format.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/src/format.rs b/common/src/format.rs index 71a8957184..d73937530d 100644 --- a/common/src/format.rs +++ b/common/src/format.rs @@ -539,7 +539,8 @@ impl FormatSpec { Ok(result) } }, - Some(FormatType::Number(_)) => self.format_int_radix(magnitude, 10), + Some(FormatType::Number(Case::Lower)) => self.format_int_radix(magnitude, 10), + Some(FormatType::Number(Case::Upper)) => Err(FormatSpecError::UnknownFormatCode('N', "int")), Some(FormatType::String) => Err(FormatSpecError::UnknownFormatCode('s', "int")), Some(FormatType::Character) => match (self.sign, self.alternate_form) { (Some(_), _) => Err(FormatSpecError::NotAllowed("Sign")), From 8c76113c85ccfb5709b27fa396ac13679d72d403 Mon Sep 17 00:00:00 2001 From: Christopher Gambrell Date: Mon, 10 Apr 2023 10:05:11 -0400 Subject: [PATCH 11/12] cargo fmt --- common/src/format.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/common/src/format.rs b/common/src/format.rs index d73937530d..896ce8138a 100644 --- a/common/src/format.rs +++ b/common/src/format.rs @@ -440,7 +440,7 @@ impl FormatSpec { Some(FormatType::Number(Case::Lower)) => { let size = magnitude.to_string().replace('.', "").len(); // If we get a precision larger than the magnitude (without the decimal), use the size. - let precision = if precision > size { size } else { precision }; + let precision = if precision > size { size } else { precision }; Ok(float_ops::format_number(magnitude, precision)) } Some(FormatType::GeneralFormat(case)) => { @@ -540,7 +540,9 @@ impl FormatSpec { } }, Some(FormatType::Number(Case::Lower)) => self.format_int_radix(magnitude, 10), - Some(FormatType::Number(Case::Upper)) => Err(FormatSpecError::UnknownFormatCode('N', "int")), + Some(FormatType::Number(Case::Upper)) => { + Err(FormatSpecError::UnknownFormatCode('N', "int")) + } Some(FormatType::String) => Err(FormatSpecError::UnknownFormatCode('s', "int")), Some(FormatType::Character) => match (self.sign, self.alternate_form) { (Some(_), _) => Err(FormatSpecError::NotAllowed("Sign")), From 509e8119b21ff4a3451de6d44fed6539bebade0e Mon Sep 17 00:00:00 2001 From: Christopher Gambrell Date: Sat, 15 Apr 2023 02:50:39 -0400 Subject: [PATCH 12/12] =?UTF-8?q?Reuse=20GeneralFormat.=20=EF=BF=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/src/float_ops.rs | 30 ------------------------------ common/src/format.rs | 8 +------- 2 files changed, 1 insertion(+), 37 deletions(-) diff --git a/common/src/float_ops.rs b/common/src/float_ops.rs index 39e4564534..cd15c2106f 100644 --- a/common/src/float_ops.rs +++ b/common/src/float_ops.rs @@ -235,36 +235,6 @@ pub fn format_general( } } -pub fn format_number(magnitude: f64, precision: usize) -> String { - let magnitude_as_string = magnitude.to_string(); - let separator_index = magnitude_as_string.chars().position(|c| c == '.').unwrap(); - if separator_index == precision { - return String::from(&magnitude_as_string[..separator_index]); - } - if separator_index < precision { - let prefix = &magnitude_as_string[0..separator_index]; - let suffix_distance = (precision - prefix.len() + 1) + separator_index; - let suffix = &magnitude_as_string[separator_index..suffix_distance]; - - return format!("{}{}", prefix, suffix); - } - format!( - "{}e+0{}", - &magnitude_as_string[..1], - get_num_of_char(&magnitude_as_string, '0') - ) -} - -fn get_num_of_char(text: &str, value: char) -> i32 { - let mut total = 0; - for char in text.chars() { - if char == value { - total += 1 - } - } - total -} - pub fn to_string(value: f64) -> String { let lit = format!("{value:e}"); if let Some(position) = lit.find('e') { diff --git a/common/src/format.rs b/common/src/format.rs index 896ce8138a..24f296a764 100644 --- a/common/src/format.rs +++ b/common/src/format.rs @@ -437,13 +437,7 @@ impl FormatSpec { let ch = char::from(self.format_type.as_ref().unwrap()); Err(FormatSpecError::UnknownFormatCode(ch, "float")) } - Some(FormatType::Number(Case::Lower)) => { - let size = magnitude.to_string().replace('.', "").len(); - // If we get a precision larger than the magnitude (without the decimal), use the size. - let precision = if precision > size { size } else { precision }; - Ok(float_ops::format_number(magnitude, precision)) - } - Some(FormatType::GeneralFormat(case)) => { + Some(FormatType::GeneralFormat(case)) | Some(FormatType::Number(case)) => { let precision = if precision == 0 { 1 } else { precision }; Ok(float_ops::format_general( precision,