在我的计算中得到额外的0.001

时间:2016-10-26 15:28:52

标签: c floating-point int

当我输入0.2作为音量我应该得到2260.00但我得到2260.001并且我无法理解为什么。即使在调整了我想要的小数数量之后,最后也总是0.1 ......

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int option;
    float volume;
    float density = 11300;
    float mass;

    while (option != 3)
    {
        printf("1: Calculate Mass\n");
        printf("2: Calculate Volume\n");
        printf("3: Exit\n");
        printf("Input here: ");
        scanf("%d", &option);

        if (option == 1)
        {
            printf("Input Volume: ");
            scanf("%f", &volume);

            mass = volume*density;
            printf("%.2f", mass);
        }

    }

   return 0;
}

0 个答案:

没有答案