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

fix(utils): fix commaize not working in RN #104

Merged
merged 4 commits into from
Oct 31, 2022

Conversation

201411108
Copy link
Contributor

Overview

I solved issue #103 and refactor converting same type issues.

PR Checklist

  • I read and included theses actions below
  1. I have read the Contributing Guide
  2. I have written documents and tests, if needed.

@netlify
Copy link

netlify bot commented Oct 29, 2022

Deploy Preview for slash-libraries ready!

Name Link
🔨 Latest commit d5ac86b
🔍 Latest deploy log https://app.netlify.com/sites/slash-libraries/deploys/635f7617b8868a0008e63bb8
😎 Deploy Preview https://deploy-preview-104--slash-libraries.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

// maximumFractionDigits은 최대 소수점 자리수인데, default가 3입니다.
// 3자리보다 많은 수를 쓰는 경우가 있을 수도 있겠다고 생각해서 넉넉하게 10으로 잡았습니다.
return value.toLocaleString('en-us', { maximumFractionDigits: 10 });
return String(value).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1,');
Copy link
Contributor

Choose a reason for hiding this comment

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

This will make the result below:

commaizeNumber('0.1234'); // '0.1,234'

How about split value by .?

Copy link
Contributor

Choose a reason for hiding this comment

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

const numStr = String(value);
const decimalPointIndex = numStr.indexOf('.');

if (decimalPointIndex > -1) {
  ...
} else {
  ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fixed this code and check it works!
I checked other functions which using commaizeNumber. But, there are any edge cases can existed, so, I asked you for cross-check. Thanks for recommendation!

Copy link
Contributor

@hoseungme hoseungme Oct 30, 2022

Choose a reason for hiding this comment

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

How about adding some test cases to prove that commaize works correctly?

You can do it on Numbers.spec.ts.

Copy link
Contributor

Choose a reason for hiding this comment

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

test('commaizeNumber', () => {
  expect(commaizeNumber(1234.1234)).toEqual('1,234.1234');
  expect(commaizeNumber(100)).toEqual('100');
  expect(commaizeNumber(13209802)).toEqual('13,209,802');
  expect(commaizeNumber('1234.1234')).toEqual('1,234.1234');
  expect(commaizeNumber('100')).toEqual('100');
  expect(commaizeNumber('13209802')).toEqual('13,209,802');
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added some test cases and it works well!
Thank you!

Copy link
Contributor

@hoseungme hoseungme left a comment

Choose a reason for hiding this comment

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

Thanks @201411108 !

@hoseungme hoseungme merged commit 11bd50d into toss:main Oct 31, 2022
@joshuakimDwan
Copy link

joshuakimDwan commented Nov 9, 2022

Thanks! You are the best! @201411108

@201411108 201411108 deleted the fix/utils-commanize branch November 9, 2022 05:50
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.

None yet

3 participants