[fix] metrics int

This commit is contained in:
kwaroran
2023-12-06 05:29:29 +09:00
parent bcab72b801
commit 6611b0b92e

View File

@@ -27,6 +27,12 @@ export function metricaPlugin(data:string, toSystem:'metrics'|'imperial'){
}
const reg = new RegExp(`(\\d+(?:\\.\\d+)?)\\s*${from}`, 'g');
data = data.replace(reg, (_, value) => {
// if value is integer, parse it as integer
if(value.indexOf('.') === -1){
const result = parseInt(value) * ratio
return `${result.toFixed(0)} ${to}`;
}
const result = parseFloat(value) * ratio;
return `${result.toFixed(2)} ${to}`;
});