Last active
July 28, 2022 04:34
-
-
Save andy4thehuynh/b88f22d8a534fed38a9899f1c898c7fa to your computer and use it in GitHub Desktop.
Takes a float and determines if should add percentage or dash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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