mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-12 20:24:43 +08:00
918a11a0b0
Co-authored-by: Anton <anton@scinote.net>
9 lines
285 B
JavaScript
9 lines
285 B
JavaScript
/* eslint-disable no-unused-vars */
|
|
|
|
function formatDecimalValue(value, decimals) {
|
|
let decimalValue = value.replace(/[^-0-9.]/g, '');
|
|
if (decimals === 0) {
|
|
return decimalValue.split('.')[0];
|
|
}
|
|
return decimalValue.match(new RegExp(`^-?\\d*(\\.\\d{0,${decimals}})?`))[0];
|
|
}
|