Translates Amount of aUnit1 to Amount of aUnit2.
(long aAmount, long aOriginalUnit, long aTargetUnit, boolean aRoundUp)
| 1675 | |
| 1676 | /** Translates Amount of aUnit1 to Amount of aUnit2. */ |
| 1677 | public static long units(long aAmount, long aOriginalUnit, long aTargetUnit, boolean aRoundUp) { |
| 1678 | if (aTargetUnit == 0) return 0; |
| 1679 | if (aOriginalUnit == aTargetUnit || aOriginalUnit == 0) return aAmount; |
| 1680 | if (aOriginalUnit % aTargetUnit == 0) {aOriginalUnit /= aTargetUnit; aTargetUnit = 1;} else |
| 1681 | if (aTargetUnit % aOriginalUnit == 0) { aTargetUnit /= aOriginalUnit; aOriginalUnit = 1;} |
| 1682 | return Math.max(0, ((aAmount * aTargetUnit) / aOriginalUnit) + (aRoundUp && (aAmount * aTargetUnit) % aOriginalUnit > 0 ? 1 : 0)); |
| 1683 | } |
| 1684 | |
| 1685 | /** Translates Amount of aUnit1 to Amount of aUnit2. With additional checks to avoid 64 Bit Overflow. */ |
| 1686 | public static long units_(long aAmount, long aOriginalUnit, long aTargetUnit, boolean aRoundUp) { |
no outgoing calls
no test coverage detected