Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nf() not rounding correctly fixed #5962

Closed

Conversation

aditya-shrivastavv
Copy link
Contributor

Resolves #5959

File Changed = src/utilities/string_functions.js

Problem:

  • nf() call doNf() when it detects a number
  • previously the doNf() was just truncating the number i.e. not rounding off

Changes:

  • inside doNf() , i added another utility function which rounds off the decimal part of the number correctly
  • the added function named roundOffDecPart modifies the decPart but does not truncate it.
  • the modified decPart is return to the doNf() which then truncates the decPart according to the right value.

Outcomes of the change:
As mentioned in the issue decription, the improper rounding of the digits of Math.PI is fixed successfully.
Successfully tested it many times at all sorts of possible inputs

PR Checklist

@welcome
Copy link

welcome bot commented Jan 19, 2023

🎉 Thanks for opening this pull request! Please check out our contributing guidelines if you haven't already. And be sure to add yourself to the list of contributors on the readme page!

@aditya-shrivastavv aditya-shrivastavv changed the title Nf func fix nf() not rounding correctly fixed Jan 19, 2023
aditya-shrivastavv added a commit to aditya-shrivastavv/p5.js that referenced this pull request Jan 19, 2023
recommended by welcome bot on my PR `nf() not rounding correctly fixed processing#5962`
@limzykenneth
Copy link
Member

Hi @aditya-shrivastavv, in #5959 @akp660 has already indicated and been assigned to work on the issue so I will be prioritizing their work on this and I'm going to close this for now.

PS. Also as mentioned in #5710, Number.toFixed() is a possible solution and there's no need to manually implement rounding.

@aditya-shrivastavv
Copy link
Contributor Author

okay then let this be closed for now. I will try to implement it with Number.toFixed(). If the assignee is not able to work through it. this PR will be helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

nf() not rounding correctly
2 participants