我可以想到的两种方式,无论是演员还是四舍五入 std::floor
int main()
{
const auto foo = 13.53;
auto firstWay = foo - static_cast<long long>(foo); // Truncating via cast and subtracting
auto otherWay = foo - std::floor(foo); // Rounding down and subtracting
return 0;
}
Run Code Online (Sandbox Code Playgroud)
快速工作台结果显示该fmod方法是迄今为止最慢的选项,而演员是最快的:QuickBench