Skip to content
This repository was archived by the owner on Nov 2, 2021. It is now read-only.

Issue #2485 - Fix rounding Error #2486

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions src/components/StateMeta.js
Original file line number Diff line number Diff line change
@@ -59,6 +59,24 @@ function StateMeta({stateCode, data, timeseries}) {
const growthRate =
(Math.pow(lastConfirmed / prevWeekConfirmed, 1 / 7) - 1) * 100;

const percentageDescription = (percentageValue, description) => {
let confirmedCasesText

if (percentageValue > 0 && percentageValue < 1)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A small inconsistency here

  • Since percentageDescription is always called for percentageValue > 0 , no need to check for percentageValue > 0
  • Its good to test percentageValue > 0 but a case when percentage value <= 0 has to be handled then

{
confirmedCasesText = "For every 1000 confirmed cases";
percentageValue = percentageValue * 10

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For semantics sake, i wouldn't call it percentageValue anymore, preferably return it here or use a more appropriate name

}
else
{
confirmedCasesText = "For every 100 confirmed cases";
}

return `${t(confirmedCasesText)},
~${formatNumber(Math.round(percentageValue))}
${t(description)}`
}

return (
<>
<div className="StateMeta population">
@@ -103,9 +121,7 @@ function StateMeta({stateCode, data, timeseries}) {
formula={'(active / confirmed) * 100'}
description={
activePercent > 0
? `${t('For every 100 confirmed cases')}, ~${formatNumber(
Math.round(activePercent)
)} ${t('are currently infected.')}`
? percentageDescription(activePercent, "are currently infected.")
: t('Currently, there are no active cases in this state.')
}
/>
@@ -117,9 +133,7 @@ function StateMeta({stateCode, data, timeseries}) {
formula={'(recovered / confirmed) * 100'}
description={
recoveryPercent > 0
? `${t('For every 100 confirmed cases')}, ~${formatNumber(
Math.round(recoveryPercent)
)} ${t('have recovered from the virus.')}`
? percentageDescription(recoveryPercent, "have recovered from the virus.")
: t('Unfortunately, there are no recoveries in this state yet.')
}
/>
@@ -131,9 +145,7 @@ function StateMeta({stateCode, data, timeseries}) {
formula={'(deceased / confirmed) * 100'}
description={
deathPercent > 0
? `${t('For every 100 confirmed cases')}, ~${formatNumber(
Math.round(deathPercent)
)} ${t('have unfortunately passed away from the virus.')}`
? percentageDescription(deathPercent, "have unfortunately passed away from the virus.")
: t(
'Fortunately, no one has passed away from the virus in this state.'
)