Corda 中的金额实例

Amount instance in Corda

我正在尝试在 Corda 中创建 'Amount' 的实例。我向它传递了一个 long 值和一个 USD 实例。

val amount = Amount(value, Currency.getInstance("USD"))

其中值为 10。

我希望输出为 10 美元,但返回为 0.10 美元,这符合预期。

我也知道美元在小数点右边有两位数。
但是有没有办法得到我想要的解决方案呢?

注意:我期望的类型是 Amount

Amount<Currency> a = new Amount<>(10, new BigDecimal("1"), Currency.getInstance("USD"));

Amount(quantity: Long, displayTokenSize: BigDecimal, token: T)

Amount represents a positive quantity of some token (currency, asset, etc.), measured in quantity of the smallest representable units. The nominal quantity represented by each individual token is equal to the displayTokenSize. The scale property of the displayTokenSize should correctly reflect the displayed decimal places and is used when rounding conversions from indicative/displayed amounts in BigDecimal to Amount occur via the Amount.fromDecimal method.

Amount.fromDecimal( new BigDecimal("10"), Currency.getInstance("USD"))

fun fromDecimal(displayQuantity: BigDecimal, token: T, rounding: RoundingMode = RoundingMode.FLOOR):

Amount 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.

https://api-prod.corda.net/api/corda-os/4.8/html/api/kotlin/corda/net.corda.core.contracts/-amount/