forked from extern/nushell
Stop nu panicks in math.round on a large decimal value(Most of the time) (#3224)
* Stop crashing when dealing with large numbers in math round * Fix formatting * add tests * just to trigger wasm build * trigger wasm build
This commit is contained in:
@ -76,9 +76,12 @@ fn round_big_int(val: BigInt) -> Value {
|
||||
|
||||
fn round_big_decimal(val: BigDecimal, precision: i64) -> Value {
|
||||
if precision > 0 {
|
||||
UntaggedValue::decimal(val.round(precision)).into()
|
||||
UntaggedValue::decimal(val.with_scale(precision + 1).round(precision)).into()
|
||||
} else {
|
||||
let (rounded, _) = val.round(precision).as_bigint_and_exponent();
|
||||
let (rounded, _) = val
|
||||
.with_scale(precision + 1)
|
||||
.round(precision)
|
||||
.as_bigint_and_exponent();
|
||||
UntaggedValue::int(rounded).into()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user