Search code examples
jsfdoubleroundingmoney-format

JSF f:convertNumber round up currency


is it possible to use f:convertNumber to round up? I checked the api here and it didn't mention anything about rounding. If not, what is the next best thing to convert a double to a $ value while rounding it up?

<f:convertNumber maxFractionDigits="2" groupingUsed="true" currencySymbol="$" maxIntegerDigits="7" type="currency" />

Ex: $1.104999 should become $1.11


Solution

  • This works for my specific case. But will it have any other edge cases that will break?

    First, round it in my java class:

    private double roundCost(double cost) {
        return (Math.ceil(cost*100))/100;
    }
    

    Then past that to my f:convertNumber.

    I'm open to other suggestions.