我在我的代码中执行减法运算,并将接收的结果转换为字符串.结果可能大于0或负数.如果结果为否定,则" - "会自动添加到结果字符串中.
我需要添加'+'符号,如果我收到了正确的结果.请告诉我最简单的方法.
我的代码:
return String.valueOf(settlingScoreMap.get(market.getSettlingScore()).getAway()
- settlingScoreMap.get(market.getSettlingScore()).getHome());
Run Code Online (Sandbox Code Playgroud)
And*_*ner 12
用途String.format:
String.format("%+d", theIntValueToPrint)
^ This indicates that the sign should be added.
Run Code Online (Sandbox Code Playgroud)