Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-1408

NumberUtils: Rounding utilities for BigDecimal to primitive double avoiding NPEs.

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 3.8
    • None
    • None

    Description

      For the sake of formatting rounded BigDecimal values in JSON/XML I'm looking for the following methods:

      1.

      public static double toDouble(BigDecimal value);
      

      that defaults to 0 when value is null.

      2.

      public static double toDouble(BigDecimal value, double defaultValue);
      

      that essentially does the same as 1. but accommodates for default values being specified.

      3.

      public static BigDecimal toScaledBigDecimal(BigDecimal value, Integer scale, RoundingMode roudingMode);
      that converts a {{BigDecimal}} to a {{BigDecimal}} whose scale is the specified value with input rounding mode applied
      

      4.

      public static BigDecimal toScaledBigDecimal(BigDecimal value);
      

      that converts a BigDecimal to a BigDecimal whose scale is 2 with RoundingMode.HALF_UP rounding mode applied.

      5.

      public static BigDecimal toScaledBigDecimal(Float value, Integer scale, RoundingMode roudingMode);
      

      that converts a Float to a BigDecimal whose scale is the specified value with input rounding mode applied.

      6.

      public static BigDecimal toScaledBigDecimal(Double value, Integer scale, RoundingMode roudingMode);
      

      that converts a Double to a BigDecimal whose scale is the specified value with input rounding mode applied.

      7.

      public static BigDecimal toScaledBigDecimal(Double value);
      

      that converts a Double to a BigDecimal whose scale is 2 with RoundingMode.HALF_UP rounding mode applied.

      8.

      public static BigDecimal toScaledBigDecimal(String value, Integer scale, RoundingMode roudingMode);
      

      that converts a String to a BigDecimal whose scale is the specified value with input rounding mode applied

      9.

      public static BigDecimal toScaledBigDecimal(String value);
      

      that converts a String to a BigDecimal whose scale is 2 with RoundingMode.HALF_UP rounding mode applied

      Attachments

        Activity

          People

            chtompki Rob Tompkins
            chtompki Rob Tompkins
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: