getValueInUnit method

double getValueInUnit(
  1. EtherUnit unit
)

Gets the value of this amount in the specified unit. WARNING: Due to rounding errors, the return value of this function is not reliable, especially for larger amounts or smaller units. While it can be used to display the amount of ether in a human-readable format, it should not be used for anything else.

Implementation

double getValueInUnit(EtherUnit unit) {
  final factor = _factors[unit]!;
  final value = _value ~/ factor;
  final remainder = _value.remainder(factor);

  return value.toInt() + (remainder.toInt() / factor.toInt());
}