scinote-web/app/assets/javascripts/sitewide/decimal_formatter.js
aignatov-bio 918a11a0b0
Fix decimal render function [SCI-6742] (#4037)
Co-authored-by: Anton <anton@scinote.net>
2022-04-20 11:07:37 +02:00

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];
}