Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 438
dave Avatar asked Sep 07 '25 07:09

dave


1 Answers

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.

like image 53
TimoStaudinger Avatar answered Sep 08 '25 22:09

TimoStaudinger