-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(currency-number): created helper with docs (#231)
Co-authored-by: Michael Amaral <[email protected]>
- Loading branch information
Showing
6 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# `currencyToNumber` | ||
|
||
Parse brazilian currency string to number format. | ||
|
||
## Arguments | ||
|
||
- `currency: string`: currency value to be format | ||
|
||
## Returns | ||
|
||
- `value: number`: A number | ||
|
||
## Usage | ||
|
||
```jsx | ||
import { currencyToNumber } from '@platformbuilders/helpers'; | ||
|
||
currencyToNumber('R$ 1000,00'); // return 1000 | ||
``` |
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { currencyToNumber } from '../currencyToNumber'; | ||
|
||
describe('currencyToNumber tests', () => { | ||
it('should parse to thousands', () => { | ||
const parsed = currencyToNumber('R$ 1000,00'); | ||
expect(parsed).toBe(1000); | ||
}); | ||
it('should parse to thousands with decimals', () => { | ||
const parsed = currencyToNumber('R$ 1000,10'); | ||
expect(parsed).toBe(1000.1); | ||
}); | ||
}); |
This file contains 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const currencyToNumber = (currency: string): number => | ||
parseFloat(currency.replace('R$', '').replace('.', '').replace(',', '.')); |
This file contains 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