mirror of
https://github.com/PaddiM8/kalker.git
synced 2025-01-21 20:48:34 +01:00
Fixed output not displaying small-ish decimal numbers properly.
This commit is contained in:
parent
d0536d6bd6
commit
aeed8049fc
@ -134,11 +134,11 @@ pub mod special_funcs {
|
||||
}
|
||||
|
||||
pub fn to_degrees(x: Float) -> Float {
|
||||
Float::with_val(10, x.to_f64().to_degrees())
|
||||
Float::with_val(53, x.to_f64().to_degrees())
|
||||
}
|
||||
|
||||
pub fn to_radians(x: Float) -> Float {
|
||||
Float::with_val(10, x.to_f64().to_radians())
|
||||
Float::with_val(53, x.to_f64().to_radians())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,21 +9,19 @@ pub fn eval(parser: &mut parser::Context, input: &str) {
|
||||
|
||||
if result.is_infinite() {
|
||||
print_err("Too big to process.");
|
||||
/*} else if result.clone().fract() == 0 {
|
||||
println!("{}", result.to_integer().unwrap());*/
|
||||
} else {
|
||||
let use_sci_notation = exp > 8 || exp < -6;
|
||||
let comma_pos = if use_sci_notation { 1 } else { exp as usize };
|
||||
let sign = if result >= 0 { "" } else { "-" };
|
||||
|
||||
let num = if use_sci_notation {
|
||||
let num = if exp <= 0 {
|
||||
// 0 < x < 1
|
||||
format!("0.{}{}", "0".repeat(exp.abs() as usize), digits)
|
||||
} else if use_sci_notation || result.fract() != 0 {
|
||||
// Insert the comma if there are supposed to be decimals.
|
||||
let mut chars: Vec<char> = digits.trim_end_matches('0').chars().collect();
|
||||
chars.insert(comma_pos, '.');
|
||||
chars.into_iter().collect::<String>()
|
||||
} else if exp < 0 {
|
||||
// 0 < x < 1
|
||||
format!("0.{}{}", "0".repeat(exp.abs() as usize), digits)
|
||||
} else {
|
||||
// Regular number
|
||||
digits[..(exp as usize)].to_string()
|
||||
|
Loading…
Reference in New Issue
Block a user