The %
operator is for integers. You’re looking for the fmod()
function.
#include <cmath>
int main()
{
double x = 6.3;
double y = 2.0;
double z = std::fmod(x,y);
}
More Related Contents:
- Why do people say there is modulo bias when using a random number generator?
- Can’t Mod Zero?
- How to code a modulo (%) operator in C/C++/Obj-C that handles negative numbers
- Why does C++ output negative numbers when using modulo?
- Is there any alternative to using % (modulus) in C/C++?
- Calculate a*a mod n without overflow
- Modular Exponentiation for high numbers in C++
- Using an iterator to Divide an Array into Parts with Unequal Size
- Fast division/mod by 10ˣ
- C++ operator % guarantees
- C++11 does not deduce type when std::function or lambda functions are involved
- How to make cin take only numbers
- What does “default” mean after a class’ function declaration?
- Checking if this is null
- What does the standard say about how calling clear on a vector changes the capacity?
- Detecting the parameter types in a Spirit semantic action
- Random array generation with no duplicates
- How are circular #includes resolved?
- How can currying be done in C++?
- How to set breakpoints on future shared libraries with a command flag
- Using CreateWindowEx to Make a Message-Only Window
- cmath vs math.h (And similar c-prefixed vs .h extension headers)
- Convert Eigen Matrix to C array
- std::vector resize downward
- Is it possible to use signal inside a C++ class?
- freopen() equivalent for c++ streams
- Parse string containing numbers into integer array
- Dependent scope and nested templates
- sizeof an array passed as function argument [duplicate]
- What does slicing mean in C++?