code: def formula_double_format(afloat, ignore_ones=True, tol=1e-8):
      
      if ignore_ones and afloat == 1:
          return ""
      elif abs(afloat - int(afloat)) < tol:
          return str(int(afloat))
      else:
          return str(round(afloat, 8))
docs: This function is used to make pretty formulas by formatting the amounts.
      Instead of Li1.0 Fe1.0 P1.0 O4.0, you get LiFePO4.
  
      Args:
          afloat (float): a float
          ignore_ones (bool): if true, floats of 1 are ignored.
          tol (float): Tolerance to round to nearest int. i.e. 2.0000000001 -> 2
  
      Returns:
          A string representation of the float for formulas.