mirror of
https://github.com/nushell/nushell
synced 2024-12-28 05:53:09 +00:00
add ability to do into int on floats using a radix (#6033)
This commit is contained in:
parent
c2f8f4bd9b
commit
ad9449bf00
1 changed files with 26 additions and 1 deletions
|
@ -169,7 +169,32 @@ pub fn action(input: &Value, span: Span, radix: u32, little_endian: bool) -> Val
|
||||||
}
|
}
|
||||||
Value::Filesize { val, .. } => Value::Int { val: *val, span },
|
Value::Filesize { val, .. } => Value::Int { val: *val, span },
|
||||||
Value::Float { val, .. } => Value::Int {
|
Value::Float { val, .. } => Value::Int {
|
||||||
val: *val as i64,
|
val: {
|
||||||
|
if radix == 10 {
|
||||||
|
*val as i64
|
||||||
|
} else {
|
||||||
|
match convert_int(
|
||||||
|
&Value::Int {
|
||||||
|
val: *val as i64,
|
||||||
|
span,
|
||||||
|
},
|
||||||
|
span,
|
||||||
|
radix,
|
||||||
|
)
|
||||||
|
.as_i64()
|
||||||
|
{
|
||||||
|
Ok(v) => v,
|
||||||
|
_ => {
|
||||||
|
return Value::Error {
|
||||||
|
error: ShellError::UnsupportedInput(
|
||||||
|
"Could not convert float to integer".to_string(),
|
||||||
|
span,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
span,
|
span,
|
||||||
},
|
},
|
||||||
Value::String { val, .. } => {
|
Value::String { val, .. } => {
|
||||||
|
|
Loading…
Reference in a new issue