function roundAndPad(num, decimalPlaces) {
if (num === '' || num === null || num === undefined || isNaN(num)) {
console.log('Invalid input');
return '-';
}
if (decimalPlaces === undefined) {
return num.toString();
}
let rounded = _.round(num, decimalPlaces);
let str = rounded.toString();
let decimalIndex = str.indexOf('.');
if (decimalIndex === -1 && decimalPlaces > 0) {
str += '.' + '0'.repeat(decimalPlaces);
} else if (decimalIndex !== -1) {
let actualDecimalPlaces = str.length - decimalIndex - 1;
str += '0'.repeat(Math.max(0, decimalPlaces - actualDecimalPlaces));
}
return str;
}
console.log(roundAndPad(158.9872, 2));