gpt4 book ai didi

java - 设置 JOptionPane 中字符串值的格式

转载 作者:行者123 更新时间:2023-12-02 04:52:11 24 4
gpt4 key购买 nike

我想要格式化一个字符串,因此读取的值不是 1.599999,而是 1.59。对于程序的其余部分,我一直在使用: %.2f 来格式化 JLabels,但是当我尝试在 JOptionPane 中执行此操作时,它不会将其识别为格式代码,而是将其识别为文本。

编辑:

  amountEntered = JOptionPane.showInputDialog(finishPayInput, "Please enter the full total of: £%.2f" + convPrice);

最佳答案

amountEntered = JOptionPane.showInputDialog(finishPayInput,
String.format("Please enter the full total of: £%.2f", convPrice))

关于java - 设置 JOptionPane 中字符串值的格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29126591/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com