dave
dave

Reputation: 41

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. 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?

Upvotes: 4

Views: 2881

Answers (1)

TimoStaudinger
TimoStaudinger

Reputation: 42450

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.

Upvotes: 2

Related Questions