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

Add Round function #66

Closed
wants to merge 0 commits into from
Closed

Add Round function #66

wants to merge 0 commits into from

Conversation

shan-shaji
Copy link

Closes #61

@shan-shaji shan-shaji marked this pull request as ready for review September 4, 2022 18:42
src/number.ts Outdated Show resolved Hide resolved
src/number.ts Outdated Show resolved Hide resolved
src/number.ts Outdated Show resolved Hide resolved
@shan-shaji
Copy link
Author

Hey, @GadQ I have made the suggested changes.

cc: @rayepps

yarn.lock Outdated Show resolved Hide resolved
@shan-shaji shan-shaji changed the title Add a Round function Add Round function Sep 26, 2022
Copy link
Owner

@sodiray sodiray left a comment

Choose a reason for hiding this comment

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

Overall, looks good. I appreciate the work @shan-shaji 🎉 A few comments.

@@ -0,0 +1,7634 @@
{
Copy link
Owner

Choose a reason for hiding this comment

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

Radash uses yarn (and yarn.lock) to track dependencies so we don't want to commit this package-lock.json file.

src/number.ts Outdated
@@ -13,3 +13,10 @@ export const toInt = (value: any, defaultValue: number = 0) => {
const result = parseInt(value)
return isNaN(result) ? defaultValue : result
}

export const round = (value: number, precision?: number): number => {
Copy link
Owner

Choose a reason for hiding this comment

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

I think we should default the precision arg to something common. If I call round(2.239) and I get back 2.239 that is probably unexpected and unhelpful in most cases. Defaulting this to a precision of 2 might make sense?

I could be wrong about this, what do you think?

Copy link
Author

Choose a reason for hiding this comment

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

That's nice @rayepps i will work on it.

Comment on lines 48 to 51
test('rounds 20.456 with precision 2', () => {
const result = _.round(20.456, 2);
assert.strictEqual(result, 20.46);
})
Copy link
Owner

Choose a reason for hiding this comment

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

I'd love to see a few more test cases here that cover common rounding at different precisions. Just a few

  • 0.005 at precision 1?
  • 19.9999 at precision 4?
  • 2.5 at precision 9

It might seem a bit dull but when it comes to rounding it could impact finance/cost/price so better very very safe than sorry.

@aleclarson
Copy link

Hi @shan-shaji, would you like to continue work on this PR over at radashi-org/radashi, a new actively maintained fork of Radash? Please let me know! 😄

@shan-shaji
Copy link
Author

Yeah sure @aleclarson i can work on it.

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.

Add a Round function
4 participants