Rob Tompkins created LANG-1408:
----------------------------------

             Summary: NumberUtils: Rounding utilities for BigDecimal to 
primitive double avoiding NPEs.
                 Key: LANG-1408
                 URL: https://issues.apache.org/jira/browse/LANG-1408
             Project: Commons Lang
          Issue Type: Improvement
            Reporter: Rob Tompkins
            Assignee: Rob Tompkins
             Fix For: 3.8


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

1. 
{code:java}
public static double toDouble(BigDecimal value);
{code}
that defaults to {{0}} when {{value}} is null.

2.
{code:java}
public static double toDouble(BigDecimal value, double defaultValue);
{code}
that essentially does the same as 1. but accommodates for default values being 
specified.

3. 
{code:java}
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
{code}

4. 
{code:java}
public static BigDecimal toScaledBigDecimal(BigDecimal value);
{code}
that converts a {{BigDecimal}} to a {{BigDecimal}} whose scale is 2 with 
{{RoundingMode.HALF_UP}} rounding mode applied.

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

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

7.
{code:java}
public static BigDecimal toScaledBigDecimal(Double value);
{code}
that converts a {{Double}} to a {{BigDecimal}} whose scale is 2 with 
{{RoundingMode.HALF_UP}} rounding mode applied.

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

9.
{code:java}
public static BigDecimal toScaledBigDecimal(String value);
{code}
that converts a {{String}} to a {{BigDecimal}} whose scale is 2 with 
{{RoundingMode.HALF_UP}} rounding mode applied



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to