I have the following code for currency formatting
boolean isNegative = probe.nl_price!=null && probe.nl_price.signum() == -1;
String str = "Price: " + (isNegative ? "-" :"") + "$" + FormatUtils.getFormatInstance().format(probe.nlr_price.abs())
Is there more elgant way to rewrite it?
nl_price
andnlr_price
with some explication? It's also strange that you don't use the getters for last 2 classes but acces the variable directly. I have a feeling that we can refactor there so this can be better. \$\endgroup\$probe.nl_price
isnull
, aNullPointerException
will be thrown atprobe.nlr_price.abs()
. So checking for it before for the sign is useless. \$\endgroup\$