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.
浮動小数点の double 変数値を 2 つの浮動小数点のみに変換するコードを教えてください。
たとえば、10.1234 を 10.12 に変更する場合は、これを試してみてください。
import java.text.DecimalFormat; ... DecimalFormat df = new DecimalFormat("#.##"); double num = 10.1234; double newNum = Double.parseDouble(df.format(num)); System.out.println(newNum);