Amount.Companion
Keywords: net.corda.core.contracts.Amount.Companion class
Date: 2023-09-18

net.corda.core.contracts

## Class Amount.Companion

- net.corda.core.contracts.Amount.Companion

- Enclosing class:
    Amount<T>

      public static class Amount.Companion

- - ### Method Detail

    - #### fromDecimal

          @JvmStatic
           @JvmOverloads
           @NotNull
          public <T> Amount<T> fromDecimal(@NotNull
                                                                               java.math.BigDecimal displayQuantity,
                                                                               @NotNull
                                                                               T token,
                                                                               @NotNull
                                                                               java.math.RoundingMode rounding)

      Build an Amount from a decimal representation. For example, with an input of "12.34 GBP", returns an amount with a quantity of "1234" tokens. The function `getDisplayTokenSize` is used to determine the conversion scaling, for example bonds might be in nominal amounts of 100, currencies in 0.01 penny units.

      Throws:
        `ArithmeticException` - if the intermediate calculations cannot be converted to an unsigned 63-bit token amount.
      See Also:
        `getDisplayTokenSize`, `Amount.toDecimal`

    - #### fromDecimal

          @JvmStatic
           @JvmOverloads
           @NotNull
          public <T> Amount<T> fromDecimal(@NotNull
                                                                               java.math.BigDecimal displayQuantity,
                                                                               @NotNull
                                                                               T token)

      Build an Amount from a decimal representation. For example, with an input of "12.34 GBP", returns an amount with a quantity of "1234" tokens. The function `getDisplayTokenSize` is used to determine the conversion scaling, for example bonds might be in nominal amounts of 100, currencies in 0.01 penny units.

      Throws:
        `ArithmeticException` - if the intermediate calculations cannot be converted to an unsigned 63-bit token amount.
      See Also:
        `getDisplayTokenSize`, `Amount.toDecimal`

    - #### zero

          @JvmStatic
           @NotNull
          public <T> Amount<T> zero(@NotNull
                                                         T token)

      For a particular token returns a zero sized Amount

    - #### getDisplayTokenSize

          @JvmStatic
           @NotNull
          public java.math.BigDecimal getDisplayTokenSize(@NotNull
                                                                               java.lang.Object token)

      Determines the representation of one Token quantity in BigDecimal. For Currency and Issued the definitions is taken from Currency defaultFractionDigits property e.g. 2 for USD, or 0 for JPY so that the automatic token size is the conventional minimum penny amount. For other possible token types the asset token should implement TokenizableAssetInfo to correctly report the designed nominal amount.

    - #### sumOrNull

          @JvmStatic
           @Nullable
          public <T> Amount<T> sumOrNull(@NotNull
                                                               java.lang.Iterable<net.corda.core.contracts.Amount> $this$sumOrNull)

      If the given iterable of `class Amount`s yields any elements, sum them, throwing an IllegalArgumentException if any of the token types are mismatched; if the iterator yields no elements, return null.

      See Also:
        `class Amount`, IllegalArgumentException

    - #### sumOrThrow

          @JvmStatic
           @NotNull
          public <T> Amount<T> sumOrThrow(@NotNull
                                                               java.lang.Iterable<net.corda.core.contracts.Amount> $this$sumOrThrow)

      Sums the amounts yielded by the given iterable, throwing an IllegalArgumentException if any of the token types are mismatched.

      See Also:
        IllegalArgumentException

    - #### sumOrZero

          @JvmStatic
           @NotNull
          public <T> Amount<T> sumOrZero(@NotNull
                                                              java.lang.Iterable<net.corda.core.contracts.Amount> $this$sumOrZero,
                                                              @NotNull
                                                              T token)

      If the given iterable of `class Amount`s yields any elements, sum them, throwing an IllegalArgumentException if any of the token types are mismatched; if the iterator yields no elements, return a zero amount of the given token type.

      See Also:
        `class Amount`, IllegalArgumentException

    - #### parseCurrency

          @JvmStatic
           @NotNull
          public Amount<java.util.Currency> parseCurrency(@NotNull
                                                                               java.lang.String input)

      Returns an amount that is equal to the given currency amount in text. Examples of what is supported:

      - 12 USD

      - 14.50 USD

      - 10 USD

      - 30 CHF

      - $10.24

      - £13

      - €5000

      Note this method does NOT respect internationalisation rules: it ignores commas and uses . as the decimal point separator, always. It also ignores the users locale:

      - $ is always USD,

      - £ is always GBP

      - € is always the Euro

      - ¥ is always Japanese Yen.

      - ₽ is always the Russian ruble.

      Thus an input of $12 expecting some other countries dollar will not work. Do your own parsing if you need correct handling of currency amounts with locale-sensitive handling.

      Throws:
        `IllegalArgumentException` - if the input string was not understood.