This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Inacurate precision truncating.

Hi folk,
I have

u16 wTemp = 0;
fsingle fTemp = 17.5123;

wTemp = (u16)fTemp;

Somehow, the wTemp is 17. Technically, the wTemp should be 18, do anybody know what do I have to do for the compiler in order to generate more precise data conversion???

Thanks!

Parents
  • Thanks folks,
    I used Dan's method, it will definitely work for my situation. I know for sure my floating point is always positive numbers.
    Neither floor() nor ceil() will not solve the problem.

    y = floor(3.53);
    y will be 3, which is should be 4.
    The round off should occur at 0.4 or 0.5
    Unless my definition of round off is different than others.
    
    Dan, How do you handle your negative values?

Reply
  • Thanks folks,
    I used Dan's method, it will definitely work for my situation. I know for sure my floating point is always positive numbers.
    Neither floor() nor ceil() will not solve the problem.

    y = floor(3.53);
    y will be 3, which is should be 4.
    The round off should occur at 0.4 or 0.5
    Unless my definition of round off is different than others.
    
    Dan, How do you handle your negative values?

Children