如何将逗号添加到 Anylogic 演示文稿文本对象中的数字字符串?

How do I add commas to numeric strings in an Anylogic presentation text object?

我在 Anylogic 演示文稿中有一个文本对象,代码如下: "Infrastructure costs: £" + Math.round(flowOpRoomsPCN) + "/day"

此文本显示:基础设施成本:£123456789/天

我希望这样显示:基础设施成本:123,456,789 英镑/天

看似简单的问题,但目前还找不到答案。

您可以使用标准 Java 格式

DecimalFormat formatter = new DecimalFormat("#,###.00");

"Infrastructure costs: £" + formatter.format(Math.round(flowOpRoomsPCN)) + "/day";

您还可以使用出色的 Java 字符串格式化程序:

double value = 123_456_789.00d;
String output = String.format("Infrastructure costs: £%(,.2f/day", value);

上面的格式化指令 %(,.2f 指示字符串格式化程序接受 value 并将其表示为正数的 ###,###.## 模式和 (###, ###.00) 表示负数。

更多信息可在 Java API 文档 here 中找到。