在java中使用printf格式化问题 [英] Formatting problems using printf in java

查看:135
本文介绍了在java中使用printf格式化问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在不同的帖子中阅读了一些有关线格式化问题的人的其他答案,但是还没有找到任何有助于解决问题的内容。我也看过java文档,没有什么我做的似乎工作。

I've read a few other answers on different posts about people having specific problems with line formatting, but have not found anything that has helped enough to solve my problem. I've also looked at the java docs and nothing I have done seems to work.

最后一行代码是我想要格式化的代码。
我最好用3个十进制精度输出格式化。

The last line of code is the one I'm trying to format. I ideally want to format it with 3 decimal precision output.

Double hi = 32.22;
System.out.println("The sqrt. is = " + Math.sqrt(hi));
System.out.printf("The Sqrt Rounded Down Is: " + "/%.3d", Math.floor(Math.sqrt(hi)));

与我/%3d有什么不对,还是别的什么?我不完全理解/记住所有格式选项。

is anything wrong with me "/%.3d", or is it something else? I don't quite fully understand/remember all the formatting options.

推荐答案

尝试这样:

System.out.printf("The Sqrt Rounded Down Is: " + "%.3f", Math.floor(Math.sqrt(hi)));

这篇关于在java中使用printf格式化问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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