Trimmed end matches of dots in order to avoid numbers such as 1..

This commit is contained in:
PaddiM8 2020-06-12 21:30:03 +02:00
parent 64083eca82
commit ada3fc52f9
4 changed files with 10 additions and 6 deletions

4
Cargo.lock generated
View File

@ -138,7 +138,7 @@ dependencies = [
[[package]]
name = "kalk"
version = "0.1.8"
version = "0.1.9"
dependencies = [
"phf",
"regex",
@ -148,7 +148,7 @@ dependencies = [
[[package]]
name = "kalk_cli"
version = "0.1.7"
version = "0.1.8"
dependencies = [
"ansi_term",
"kalk",

View File

@ -1,6 +1,6 @@
[package]
name = "kalk"
version = "0.1.8"
version = "0.1.9"
authors = ["PaddiM8"]
edition = "2018"
readme = "README.md"

View File

@ -1,6 +1,6 @@
[package]
name = "kalk_cli"
version = "0.1.7"
version = "0.1.8"
authors = ["PaddiM8"]
edition = "2018"
readme = "../README.md"
@ -11,7 +11,7 @@ keywords = ["math", "calculator", "cli", "command-line"]
categories = ["mathematics", "command-line-utilities"]
[dependencies]
kalk = { path = "../kalk", version = "^0.1.8" }
kalk = { path = "../kalk", version = "^0.1.9" }
rustyline = "6.1.2"
ansi_term = "0.12"
regex = "1"

View File

@ -19,7 +19,11 @@ pub fn eval(parser: &mut parser::Context, input: &str) {
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();
let mut chars: Vec<char> = digits
.trim_end_matches('0')
.trim_end_matches('.')
.chars()
.collect();
chars.insert(comma_pos, '.');
chars.into_iter().collect::<String>()
} else {