fromSats method

String fromSats(
  1. BigInt sats
)

Obtains the string representation of the satoshis (sats) converted into this unit.

Implementation

String fromSats(BigInt sats) {

  final padded = sats.toString().padLeft(decimals+1, "0");
  final insertIdx = padded.length-decimals;
  final left = padded.substring(0, insertIdx);
  final right = padded.substring(insertIdx);
  final withPoint = "$left.$right";

  // Remove any trailing zeros and the decimal point if it comes before those
  // zeros
  return withPoint.replaceFirst(_trailZeroRegex, "");

}