Reputation: 1099
I am trying to use this function to round to decimals
function round(value, decimals) {
return Number(Math.round(value + 'e' + decimals) + 'e-' + decimals);
}
But I am getting error message
[ts] Cannot invoke an expression whose type lacks a call signature. Type 'Number' has no compatible call signatures.
Upvotes: 2
Views: 1249
Reputation: 1075219
Convert the string to a number first, for instance:
function round(value, decimals) {
return Number(Math.round(Number(value + 'e' + decimals)) + 'e-' + decimals);
// ----------------------^^^^^^^----------------------^
}
Upvotes: 4