printf%f小数点后只有2个数字? [英] printf %f with only 2 numbers after the decimal point?

查看:2047
本文介绍了printf%f小数点后只有2个数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 printf 中,我需要使用%f ,但我不知道如何截断为2小数位:

In my printf, I need to use %f but I'm not sure how to truncate to 2 decimal places:

示例:
得到

3.14159

打印为:

3.14

推荐答案

使用此:

printf ("%.2f", 3.14159);

这篇关于printf%f小数点后只有2个数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆