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

Conversation

codelear
Copy link

Description of PR

The rounding off was presenting incorrect results when the percentage was less than 1. So I fixed this by checking if the percentage is between 0 and 1 and scaling the value by 10.

Relevant Issues
Fixes #2485

Checklist

  • Compiles and passes lint tests
  • Properly formatted
  • Tested on desktop
  • Tested on phone

Screenshots

image

@codelear
Copy link
Author

codelear commented May 26, 2021

@sarathsp06 - Fixes Issue #2485

if (percentageValue > 0 && percentageValue < 1)
{
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

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

@shuklaayush
Copy link
Member

Thanks @codelear for the PR and @sarathsp06 for the inputs. This should be fixed via 2a0fba8.

I wasn't in favour of switching the text between per 100 and per 1000 based on the percentage value, so I modified the formatting logic to show decimals if the percentage is between 0 and 1. Closing this.

@shuklaayush shuklaayush closed this Jun 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0.3 rounded as 0 , makes statement wrong
3 participants