我正在尝试使用此函数舍入到小数点
function round(value, decimals) {
return Number(Math.round(value + 'e' + decimals) + 'e-' + decimals);
}
但是我收到错误消息
[ts] Cannot invoke an expression whose type lacks a call signature. Type 'Number' has no compatible call signatures.
答案 0 :(得分:2)
首先将字符串转换为数字,例如:
function round(value, decimals) {
return Number(Math.round(Number(value + 'e' + decimals)) + 'e-' + decimals);
// ----------------------^^^^^^^----------------------^
}