'How to fix double error while evaluating c++

I have a function which transforms double to int

uint32_t convert(double val) {
    return static_cast<uint32_t>(trunc(val * 1E4()); 
}

But I have problems with 1.00009999999999999 because it transforms in 10001. I know that problem with double error, but how fix it? I have tried epsilon, but it didn't help



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source