mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-18 15:13:21 +08:00
10 lines
285 B
JavaScript
10 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];
|
||
|
}
|