How to cut decimal off without rounding in C

后端 未结 5 1986
无人共我
无人共我 2020-12-01 18:11

How do I cut off decimal places in C without rounding?

For example if the number is 4.48

it will just show 4.4

%.1f

5条回答
  •  盖世英雄少女心
    2020-12-01 18:58

    If your compiler supports C99, you should be able to use trunc() and friends:

    float f = 4.56f;
    f = truncf(f * 10.0) / 10.0;
    

提交回复
热议问题