Trim trailing zeros and '.' (dot) for float numbers when generating CSV
This commit is contained in:
Родитель
856a707840
Коммит
95f2673938
|
@ -194,7 +194,7 @@ fn value_to_csv(value: &Value) -> String {
|
|||
Value::Number(ref v) => {
|
||||
if v.is_f64() {
|
||||
let mut buffer = ryu::Buffer::new();
|
||||
buffer.format(v.as_f64().unwrap()).to_owned()
|
||||
truncate_trailing_zeros(buffer.format(v.as_f64().unwrap())).to_string()
|
||||
} else if v.is_u64() {
|
||||
format!("{}", v.as_u64().unwrap())
|
||||
} else {
|
||||
|
@ -207,6 +207,10 @@ fn value_to_csv(value: &Value) -> String {
|
|||
}
|
||||
}
|
||||
|
||||
fn truncate_trailing_zeros(str: &str) -> &str {
|
||||
str.trim_end_matches('0').trim_end_matches('.')
|
||||
}
|
||||
|
||||
fn row_to_value(settings: &Settings, row: &Row) -> Result<Value, Box<dyn Error>> {
|
||||
let mut map = serde_json::Map::with_capacity(row.len());
|
||||
for i in 0..row.len() {
|
||||
|
|
Загрузка…
Ссылка в новой задаче