打字稿:“数字”类型的参数不能分配给“字符串”类型的参数

时间:2018-07-14 11:50:04

标签: typescript

试图找出在TypeScript中删除数字小数的简单方法。根据我的发现,ParseInt方法应该可以工作,但是会出现错误

objectTable

代码:

Argument of type 'number' is not assignable to parameter of type 'string'

}

2 个答案:

答案 0 :(得分:1)

scorenumberparseInt期望使用string参数,因为它的目的是按照函数名称的建议从字符串中解析整数。

如果打算返回整数部分,则不需要parseInt。相反,它应该是:

score = Math.floor(frame_count_correct/frame_count)

答案 1 :(得分:0)

您正在尝试使用parseInt函数,该函数定义为具有双类型变量的字符串变量。 你确定吗? 您可以改用Math.floor(score)

相关问题