其他分享
首页 > 其他分享> > 已知float后几位,谋几位保留

已知float后几位,谋几位保留

作者:互联网

                                              设变量n为float类型,m为int类型,则以下能实现将n中的数值保留小数点后两位,第三位进行四舍五入运算的表达式____.

#include "common.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

//#define 
static float Mathematical_modeling = 0;
static int   capacitance_modeling  = 0;
static float value = 0;
static char  car = 'A';
static float bus_num = -1000.123;
static int   China_population = -100;
static float x = 2.5, y = 4.7;
static int a = 7;
//m=         (int)
//n=1.3456   (float)
static float test_n = 1.3456;
static int   test_m = 0;

int main()
{
    
    int tmp = 2 / 4;
    test_m = test_n * 100 + 0.5;
    test_n = test_m / 100.0;

    //x+y 
    printf("类型转换is %f\n",x+a%3*(int)(x + y)%2/4);
    printf("tmp is %d\n", tmp);
    printf("test_n is %f\n",test_n);

    while (1)
    {
        getchar();
    }

    return 0;
} 

 

标签:tmp,int,float,几位,已知,static,test,include
来源: https://www.cnblogs.com/nowroot/p/12373981.html