Development
...
Basics
Token Quantities
1 min
tokens (also called assets) can have an arbitrary divisibility from zero up to eight decimals while amount is meant to be used for docid\ oxxjeao qfaprw71w9iw9 and fixed to eight decimals, another more generic value object class for arbitrary decimals is needed chainvalue https //signum network github io/signumjs/classes/util chainvalue html token amounts are called quantities and the docid\ yynxycqblmbwflxzom4c6 always returns the token quantities the suffix qnt see an example https //europe signum network/api doc/index html#get /api requesttype getasset so, a token foo can have four decimals, which would result in 1 foo = 10,000 fooqnt 1 fooqnt = 0 0001 foo similar to amount signumjs provides a value object class calls chainvalue and allows to convert and calculate with quantities const {chainvalue} = require("@signumjs/util"); // note, we define the decimals for our token const foovalue = chainvalue create(4) console log('one foo is', foovalue setcompound(1 0) getatomic(), 'fooqnt') console log('one fooqnt is', foovalue setatomic(1) getcompound(), 'foo') // attention, we need to clone foovalue to avoid an override for the calculations console log('10 foo + 245,000 fooqnt =', foovalue setcompound(10) add(foovalue clone() setatomic(245000)) getcompound(), 'foo') console log('10 foo + 245,000 fooqnt =', foovalue setcompound(10) add(foovalue clone() setatomic(245000)) getatomic(), 'fooqnt') console log('50,000 fooqnt 16 =', foovalue setatomic(50 000) multiply(16) getcompound(), 'foo') console log('2 foo < 40,000 fooqnt is ', foovalue setcompound(2) less(foovalue clone() setatomic(40 000))) // mind that multiply, add, subtract and divide mutates the value object const mutatedvalue = foovalue setcompound(1) mutatedvalue add(foovalue clone() setcompound(2 65)) console log('value is', mutatedvalue getcompound())