toXdrAmount static method

int toXdrAmount(
  1. String value
)

Implementation

static int toXdrAmount(String value) {
  List<String> two = value.split(".");
  BigInt amount = BigInt.parse(two[0]) * BigInt.from(10000000);

  if (two.length == 2) {
    int pos = 0;
    String point = two[1];
    for (int i = point.length - 1; i >= 0; i--) {
      if (point[i] == '0')
        pos++;
      else
        break;
    }
    point = point.substring(0, point.length - pos);
    int length = 7 - point.length;
    if (length < 0)
      throw Exception("The decimal point cannot exceed seven digits.");
    for (; length > 0; length--) point += "0";
    amount += BigInt.parse(point);
  }

  return amount.toInt();
}