humanizeResistance function

String humanizeResistance(
  1. double ohms
)

Formats resistance in appropriate units.

Implementation

String humanizeResistance(double ohms) {
  if (ohms >= 1e9) {
    return '${(ohms / 1e9).toStringAsFixed(2)} GΩ';
  } else if (ohms >= 1e6) {
    return '${(ohms / 1e6).toStringAsFixed(2)} MΩ';
  } else if (ohms >= 1e3) {
    return '${(ohms / 1e3).toStringAsFixed(2)} kΩ';
  } else if (ohms >= 1) {
    return '${ohms.toStringAsFixed(2)} Ω';
  } else if (ohms >= 1e-3) {
    return '${(ohms * 1e3).toStringAsFixed(2)} mΩ';
  } else {
    return '${ohms.toStringAsFixed(6)} Ω';
  }
}