diff --git a/crates/nu-command/src/conversions/into/filesize.rs b/crates/nu-command/src/conversions/into/filesize.rs index 3920deaed7..967d933b43 100644 --- a/crates/nu-command/src/conversions/into/filesize.rs +++ b/crates/nu-command/src/conversions/into/filesize.rs @@ -5,6 +5,7 @@ use nu_protocol::{ engine::{Command, EngineState, Stack}, record, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value, }; +use nu_utils::get_system_locale; #[derive(Clone)] pub struct SubCommand; @@ -137,7 +138,13 @@ pub fn action(input: &Value, _args: &CellPathOnlyArgs, span: Span) -> Value { } } fn int_from_string(a_string: &str, span: Span) -> Result { - match a_string.trim().parse::() { + // Get the Locale so we know what the thousands separator is + let locale = get_system_locale(); + + // Now that we know the locale, get the thousands separator and remove it + // so strings like 1,123,456 can be parsed as 1123456 + let no_comma_string = a_string.replace(locale.separator(), ""); + match no_comma_string.trim().parse::() { Ok(n) => Ok(n.0 as i64), Err(_) => Err(ShellError::CantConvert { to_type: "int".into(), diff --git a/crates/nu-command/src/conversions/into/int.rs b/crates/nu-command/src/conversions/into/int.rs index f29288aa0c..afe90f7fcd 100644 --- a/crates/nu-command/src/conversions/into/int.rs +++ b/crates/nu-command/src/conversions/into/int.rs @@ -6,6 +6,7 @@ use nu_protocol::{ engine::{Command, EngineState, Stack}, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value, }; +use nu_utils::get_system_locale; struct Arguments { radix: u32, @@ -400,7 +401,14 @@ fn convert_int(input: &Value, head: Span, radix: u32) -> Value { } fn int_from_string(a_string: &str, span: Span) -> Result { - let trimmed = a_string.trim(); + // Get the Locale so we know what the thousands separator is + let locale = get_system_locale(); + + // Now that we know the locale, get the thousands separator and remove it + // so strings like 1,123,456 can be parsed as 1123456 + let no_comma_string = a_string.replace(locale.separator(), ""); + + let trimmed = no_comma_string.trim(); match trimmed { b if b.starts_with("0b") => { let num = match i64::from_str_radix(b.trim_start_matches("0b"), 2) {