Why is this simple piece of code not working?

前端 未结 5 830
悲哀的现实
悲哀的现实 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 03:49

    When you perform

     fbb = bb/1000;
    

    It treats operation as int/int and returns an int

    Try

    fbb = ((double)bb)/1000.000;
    

    It will be treated as (double)/(double) and return a double.

提交回复
热议问题