Skip to content

Instantly share code, notes, and snippets.

@dexMargera
Last active April 14, 2017 08:53
Show Gist options
  • Save dexMargera/6523aaa026a07a64d34131406b9237e2 to your computer and use it in GitHub Desktop.
Save dexMargera/6523aaa026a07a64d34131406b9237e2 to your computer and use it in GitHub Desktop.
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
import java.util.Locale;
public class UberTest {
private static final Log log = LogFactory.getLog(UberTest.class);
public static void main(String[] args) throws Exception {
NumberFormat decimalFormat = new DecimalFormat("#0.00", new DecimalFormatSymbols(Locale.ENGLISH));
double d0 = 3.124;
double d1 = 3.125;
log.info(decimalFormat.format(d0));
log.info(decimalFormat.format(d1));
log.info("====");
decimalFormat.setRoundingMode(RoundingMode.HALF_UP);
log.info(decimalFormat.format(d0));
log.info(decimalFormat.format(d1));
}
}
2017-04-14 11:49:31,090 INFO [UberTest] 3.12
2017-04-14 11:49:31,090 INFO [UberTest] 3.12
2017-04-14 11:49:31,090 INFO [UberTest] ====
2017-04-14 11:49:31,098 INFO [UberTest] 3,12
2017-04-14 11:49:31,098 INFO [UberTest] 3,13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment