This repository was archived by the owner on Nov 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Issue #2485 - Fix rounding Error #2486
Closed
+21
−9
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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) | ||
{ | ||
confirmedCasesText = "For every 1000 confirmed cases"; | ||
percentageValue = percentageValue * 10 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For semantics sake, i wouldn't call it |
||
} | ||
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.' | ||
) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A small inconsistency here
percentageDescription
is always called for percentageValue > 0 , no need to check forpercentageValue > 0
percentageValue > 0
but a case when percentage value <= 0 has to be handled then