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

Viewed 49

I have a text object in the Anylogic presentation with the following code: "Infrastructure costs: £" + Math.round(flowOpRoomsPCN) + "/day"

This text displays: Infrastructure costs: £123456789/day

I would like this to display: Infrastructure costs: £123,456,789/day

Seems a simple question but could not find the answer anywhere just yet.

2 Answers

You can also use the great Java string formatter:

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

The above formatting directive %(,.2f instructs string formatter to take in value and represent it as a ###,###.## pattern for positive numbers and (###,###.00) for negative.

More information is available in Java API documentation here.

You can use standard Java formating

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

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