How to obtain the remainder in float data type using modulus operator

时间:2016-10-04 14:45:37

标签: javascript

In javascript, the modulus operator is used to obtain the remainder of a mathematical expression. The result obtained is always an integer. What is the function that is to be used to obtain the exact decimal value remainder in this case?

1 个答案:

答案 0 :(得分:1)

使用%运算符可以正常工作:



console.log(12.5 % 10) // 2.5
console.log(10 % 5.5)  // 4.5




有关参考,另请参阅MDN article on the remainder operator,概述此行为。