Why is this simple piece of code not working?

前端 未结 5 870
悲哀的现实
悲哀的现实 2021-01-26 03:36

I am trying to get a floating variable accurate to just 3 decimal points for a comparison calculation. I am trying the method below, but it doesn\'t work. I can\'t see why not,

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-26 04:07

    bb is an int, so bb / 1000 will follow the integer division. Change either or both operand to a double. The simplest way is:

    fbb = bb / 1000.0;       //type of 1000.0 is double
    

    or

    fbb = (double)bb / 1000
    

提交回复
热议问题