toFraction method

String toFraction(
  1. int? decimals
)

Returns the value as a fraction symbol, otherwise returns toStringAsPrecisionOrInt

Implementation

String toFraction(int? decimals) {
  if (this < 1) {
    if (this == 0.125 || this == 0.13) {
      return "⅛";
    } else if (this == 0.25) {
      return "¼";
    } else if (this == 0.375 || this == 0.38) {
      return "⅜";
    } else if (this == 0.5) {
      return "½";
    } else if (this == 0.625 || this == 0.63) {
      return "⅝";
    } else if (this == 0.75) {
      return "¾";
    } else if (this == 0.875 || this == 0.88) {
      return "⅞";
    } else if (this >= 0.32 && this <= 0.34) {
      return "⅓";
    } else if (this >= 0.65 && this <= 0.67) {
      return "⅔";
    }
  }
  return toStringAsPrecisionOrInt(decimals!);
}