简体   繁体   English

如何使用模数运算符获取浮点数据类型的余数

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

In javascript, the modulus operator is used to obtain the remainder of a mathematical expression.在 javascript 中,模运算符用于获取数学表达式的余数。 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?在这种情况下,用于获得精确十进制值余数的函数是什么?

This is working just fine using the % operator:使用%运算符可以正常工作:

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

For a reference, also see the MDN article on the remainder operator , outlining this behavior.有关参考,另请参阅关于余数运算符MDN 文章,概述了此行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM