Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
DecimalFormatを使用したり、何かをインポートしたりせずに、 double を末尾のゼロで小数点以下 2 桁に丸めることができるかどうかを知りたいですか? 私は過去30分間、1つを考えようとしてきましたが、わかりません.
DecimalFormat
String.format(); を使用できます。
String s = String.format("my double: %.2f", 3.54123); System.out.println(s);
または直接 printf
System.out.printf("my double: %.2f%n", 3.54123);
どうですか?
(((int)(number * 100))/100.0F)
例