浮点数指定小数点后几位

    double dTmp = 1.234;
    int tenths     = ((int)(dTmp * 10))  % 10;//十分位
    int percentile = ((int)(dTmp * 100)) % 10;//百分位
    /* 整数部分 + 小数点后一位 + 小数点后两位四舍五入 */
    double res = (int)dTmp + (double)(tenths) / 10 + (percentile >= 5 ? 0.1 : 0);

    原文作者:HZHejo
    原文地址: https://blog.csdn.net/HZHejo/article/details/124825901
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞