I am looking for removing first zero in this confidence variable
use std::{io, process};
extern crate whatlang;
use whatlang::detect;
fn main() {
println!("Type quit anytime you want to quit the program");
loop {
println!("Type something >>");
let mut text: String = String::new();
io::stdin()
.read_line(&mut text)
.expect("Failed to read the line");
let text = text.trim();
if text == "quit" {
process::exit(0);
}
let info = detect(text).expect("Failed to detect language");
let confidence = (info.confidence() * 100.0).round() / 100.0;
println!("Language: {}", info.lang());
println!("Script: {}", info.script());
println!("Confidence: {}%", confidence);
};
}
let confidence = (info.confidence() * 100.0).round() / 100.0;
confidence is documented as returning a value between 0 and 1, so if you want the percentage, you want to just multiply by 100.0. You can use formatting to only print so many digits after the decimal point: