Skip to content

Instantly share code, notes, and snippets.

@itoz
Created June 28, 2011 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itoz/1051110 to your computer and use it in GitHub Desktop.
Save itoz/1051110 to your computer and use it in GitHub Desktop.
JAVA 四捨五入
//四捨五入
BigDecimal origin = new BigDecimal(f);
BigDecimal res = origin.setScale(0,BigDecimal.ROUND_HALF_UP);
result = res.shortValue();
or
Math.round(f);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment