diff --git a/CHANGELOG.md b/CHANGELOG.md
index e3a4add0..6a8ca94a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+## 1.3.7
+
+* Adjust value of Dial total_value so that it does not show
+zero for a value that is less than 0.1
+
## 1.3.6
* Correct filenames for the habitat country CSVs - must be plural.
diff --git a/app/helpers/countries_helper.rb b/app/helpers/countries_helper.rb
index db352f2b..9afee381 100644
--- a/app/helpers/countries_helper.rb
+++ b/app/helpers/countries_helper.rb
@@ -43,10 +43,6 @@ def protected_percentage(dataset)
end
end
- def total_value(dataset)
- @country.protection_stats[dataset[:id]] ? @country.protection_stats[dataset[:id]]['total_value'].round(1) : 0
- end
-
def habitat_with_data
@red_list_data.find { |habitat| habitat['data'].present? }
end
diff --git a/app/helpers/proportion_protected_helper.rb b/app/helpers/proportion_protected_helper.rb
index 1659da5f..3f75986a 100644
--- a/app/helpers/proportion_protected_helper.rb
+++ b/app/helpers/proportion_protected_helper.rb
@@ -1,12 +1,11 @@
module ProportionProtectedHelper
def global_proportion_protected_html(dataset)
+ total_value = habitat_protection(dataset[:id])['total_value']
+
t('shared.proportion_protected.card.percentage',
percentage: habitat_protection(dataset[:id])['protected_percentage'],
- area: number_with_delimiter(
- habitat_protection(dataset[:id])['total_value'],
- delimiter: ','
- )
- ).html_safe
+ area: total_value_formatted(total_value),
+ area_unrounded: number_with_delimiter(total_value, delimiter: ',')).html_safe
end
def country_proportion_protected_status_html(dataset)
@@ -20,10 +19,12 @@ def country_proportion_protected_status_html(dataset)
end
def country_proportion_protected_html(dataset)
+ total_value = @country.protection_stats[dataset[:id]] ? @country.protection_stats[dataset[:id]]['total_value'] : 0
+
t('shared.proportion_protected.card.percentage',
percentage: protected_percentage(dataset),
- area: number_with_delimiter(total_value(dataset), delimiter: ',')
- ).html_safe
+ area: total_value_formatted(total_value),
+ area_unrounded: number_with_delimiter(total_value, delimiter: ',')).html_safe
end
def proportion_protected_percentage(dataset)
@@ -37,4 +38,14 @@ def proportion_protected_icon_class(dataset)
def proportion_protected_card_modifier(dataset)
current_page?('/') ? 'present' : dataset_status(dataset)
end
-end
\ No newline at end of file
+
+ def total_value_formatted(value)
+ if value.zero?
+ 0
+ elsif value < 0.1
+ format('%.2e', value)
+ else
+ number_with_delimiter(value.round(1), delimiter: ',')
+ end
+ end
+end
diff --git a/config/locales/shared/proportion_protected/en.yml b/config/locales/shared/proportion_protected/en.yml
index 83301ef5..29bba3f1 100644
--- a/config/locales/shared/proportion_protected/en.yml
+++ b/config/locales/shared/proportion_protected/en.yml
@@ -10,4 +10,4 @@ en:
note: 'Note: This outlines the proportion of each habitat that is known to occur within protected areas. However, the level of protection and whether or not these habitats are explicitly and effectively protected is unknown.'
last_updated: 'Last updated: %{last_updated}'
card:
- percentage: '%{percentage}% of %{area} km2'
\ No newline at end of file
+ percentage: '%{percentage}% of %{area} km2'
\ No newline at end of file