Skip to content

Instantly share code, notes, and snippets.

@andy4thehuynh
Last active July 28, 2022 04:34
Show Gist options
  • Select an option

  • Save andy4thehuynh/b88f22d8a534fed38a9899f1c898c7fa to your computer and use it in GitHub Desktop.

Select an option

Save andy4thehuynh/b88f22d8a534fed38a9899f1c898c7fa to your computer and use it in GitHub Desktop.
Takes a float and determines if should add percentage or dash
def float_to_percentage_or_dash(float, options={})
float = float.to_f
nan = options.delete(:nan) || "—".html_safe
options[:precision] ||= 0
return nan if float.nan?
float == 0 ? dash : number_to_percentage(float * 100, **options)
end
def percentage_or_dash(value)
value == 0 ? dash : value
end
def number_with_delimiter_or_dash(value)
value == 0 ? dash : number_with_delimiter(value)
end
def dash
content_tag :span, "—", class: "table-stats-nil"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment