在c ++中使用%on double

Ang*_*uck 2 c++ double operators

即时尝试在c ++中使用%运算符,我已经在java中做了同样的工作并且工作正常.

有什么东西我在这里失踪或者这是不允许的,对不起我是c ++的新手,所以可能会在这里犯一个非常愚蠢的错误

    double i =  full_price_in_pence / 100.0;
    double j = full_price_in_pence % 100;
    int final_pounds = (int) i;
    int final_pence = (int) j;
Run Code Online (Sandbox Code Playgroud)

这些都是双重值

full_price_in_pence
full_price_in_pounds
Run Code Online (Sandbox Code Playgroud)

And*_*owl 9

您应该使用标准标题中的std::fmod()函数<cmath>:

#include <cmath>

// ...

double j = fmod(full_price_in_pence, 100);
Run Code Online (Sandbox Code Playgroud)