fix: Fixed formatMm in utils display of units
This commit is contained in:
parent
798c37f886
commit
3fa2d52c8a
1 changed files with 16 additions and 8 deletions
|
@ -18,16 +18,24 @@ const formatMm = (val, units, format = 'html') => {
|
||||||
inches = Math.floor(fraction)
|
inches = Math.floor(fraction)
|
||||||
rest = fraction - inches
|
rest = fraction - inches
|
||||||
}
|
}
|
||||||
|
let suffix = ''
|
||||||
|
if (format === 'html') suffix = '"'
|
||||||
let fraction128 = Math.round(rest * 128)
|
let fraction128 = Math.round(rest * 128)
|
||||||
if (fraction128 == 0) return formatImperial(negative, inches)
|
if (fraction128 == 0) return formatImperial(negative, inches)
|
||||||
if (fraction128 % 64 == 0) return formatImperial(negative, inches, fraction128 / 64, 2, format)
|
if (fraction128 % 64 == 0)
|
||||||
if (fraction128 % 32 == 0) return formatImperial(negative, inches, fraction128 / 32, 4, format)
|
return formatImperial(negative, inches, fraction128 / 64, 2, format) + suffix
|
||||||
if (fraction128 % 16 == 0) return formatImperial(negative, inches, fraction128 / 16, 8, format)
|
if (fraction128 % 32 == 0)
|
||||||
if (fraction128 % 8 == 0) return formatImperial(negative, inches, fraction128 / 8, 16, format)
|
return formatImperial(negative, inches, fraction128 / 32, 4, format) + suffix
|
||||||
if (fraction128 % 4 == 0) return formatImperial(negative, inches, fraction128 / 4, 32, format)
|
if (fraction128 % 16 == 0)
|
||||||
if (fraction128 % 2 == 0) return formatImperial(negative, inches, fraction128 / 2, 64, format)
|
return formatImperial(negative, inches, fraction128 / 16, 8, format) + suffix
|
||||||
if (format === 'html') return negative + Math.round(fraction * 100) / 100 + '"'
|
if (fraction128 % 8 == 0)
|
||||||
else return negative + Math.round(fraction * 100) / 100
|
return formatImperial(negative, inches, fraction128 / 8, 16, format) + suffix
|
||||||
|
if (fraction128 % 4 == 0)
|
||||||
|
return formatImperial(negative, inches, fraction128 / 4, 32, format) + suffix
|
||||||
|
if (fraction128 % 2 == 0)
|
||||||
|
return formatImperial(negative, inches, fraction128 / 2, 64, format) + suffix
|
||||||
|
if (format === 'html') return negative + Math.round(fraction * 100) / 100 + suffix
|
||||||
|
else return negative + Math.round(fraction * 100) / 100 + suffix
|
||||||
} else {
|
} else {
|
||||||
if (format === 'html') return roundMm(val / 10) + 'cm'
|
if (format === 'html') return roundMm(val / 10) + 'cm'
|
||||||
else return roundMm(val / 10)
|
else return roundMm(val / 10)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue