getValueInUnit method

num getValueInUnit(
  1. ArbitUnit 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 arbit in a human-readable format, it should not be used for anything else.

Implementation

num getValueInUnit(ArbitUnit unit) {
  final factor = _factors[unit]!;
  final value = quantity ~/ factor;
  final remainder = quantity.remainder(factor);

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