java - 如何使用 Printf
问题描述
如何使用 printf 打印包含需要舍入的多个浮点数的行。我知道我需要使用 "%6.2f" 将其四舍五入到小数点后两位。我需要将变量“temp”和“v”四舍五入到小数点后两位。
我试过这个:
System.out.printf("%6.2f," temp + " " + " 华氏度" + "%6.2f," v + " " + "摄氏度");
这没有用。
System.out.printf(temp + " " + " 华氏度是 " + " " + v + " " + "摄氏度");
解决方案
这就是你要找的:
System.out.printf("%6.2f degrees Fahrenheit is %6.2f Celsius", temp, v);
推荐阅读
- python - 有没有办法检查LSD的线输出是垂直的还是水平的
- ios - 如果在 swift 中使用 session.uploadTask 上传失败,如何检查错误?
- javascript - 如何为 React 项目实现深度链接?
- python - XL Wings 的问题 - DLL 文件不是实际版本
- ios - 如何在应用程序中从系统推送通知设置跳转到个人推送通知设置?
- java - 无法弄清楚如何从配置中正确提取密钥
- php - PHP 动态运算符用法
- reactjs - 使用 Firestore 和 Next.js 为 SEO 分页数据的最佳方法
- anylogic - Anylogic叉车碰撞记录
- python - 用 pandas 操作 df