Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created July 9, 2019 14:54
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 parzibyte/225c512e1e6721160f4134299cc52bfb to your computer and use it in GitHub Desktop.
Save parzibyte/225c512e1e6721160f4134299cc52bfb to your computer and use it in GitHub Desktop.
BigDecimal numero = new BigDecimal("7.3333");
System.out.println("El número original: " + numero.toString());
// Establecer su escala y su forma de redondeo; al llamar
// a setScale se redondea
BigDecimal bdHalfUp = numero.setScale(3, RoundingMode.HALF_UP);
System.out.println("El número con RoundingMode.HALF_UP: " + bdHalfUp.toString());
BigDecimal bdCeiling = numero.setScale(3, RoundingMode.CEILING);
System.out.println("El número con RoundingMode.CEILING: " + bdCeiling.toString());
BigDecimal bdUp = numero.setScale(3, RoundingMode.UP);
System.out.println("El número con RoundingMode.UP: " + bdUp.toString());
BigDecimal bdFloor = numero.setScale(3, RoundingMode.FLOOR);
System.out.println("El número con RoundingMode.FLOOR: " + bdFloor.toString());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment