private static int calculateFractionPlaces ( BigDecimal unitCount , int scale , int minDecimals , List < Integer > fractionGroups ) { /* Taking into account BOTH the user's preference for decimal-place groups, AND the prohibition * against displaying a fractional number of satoshis, determine the maximum possible number of * fractional decimal places. */ int places = minDecimals ; for ( int group : fractionGroups ) { places += group ; } int max = Math . min ( places , offSatoshis ( scale ) ) ; places = Math . min ( minDecimals , max ) ; for ( int group : fractionGroups ) { /* Compare the value formatted using only this many decimal places to the * same value using as many places as possible. If there's no difference, then * there's no reason to continue adding more places. */ if ( unitCount . setScale ( places , HALF_UP ) . compareTo ( unitCount . setScale ( max , HALF_UP ) ) == 0 ) break ; places += group ; if ( places > max ) places = max ; } return places ; }
Return the number of fractional decimal places to be displayed when formatting the given number of monetary units of the denomination indicated by the given decimal scale value where 0 = coin 3 = millicoin and so on .