Search code examples
smartcontractsscrypto

Error when making calculations with Decimal?


When I try to calculate the fee of something, it wont work. For example if I try:

let foo: Decimal = 100.0 * 1.0

I get this error: expected Decimal, found f64

I've tried: let foo: Decimal = 100.0.into() * 10.0.into(); - still doesnt work


Solution

  • Decimal is a Scrypto type. You can only calculate Decimal with other Decimal types in Scrypt, in this case, you do:

    let foo: Decimal = Decimal::from("100.0") * Decimal::from("10.0");