generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b7ebf23
commit 7f94b05
Showing
5 changed files
with
178 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
// config for Numerable | ||
return [ | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Default Currency | ||
|-------------------------------------------------------------------------- | ||
| | ||
| This will be the default currency used when formatting a number to a | ||
| currency. You can change this value to any currency code supported by the | ||
| NumberFormatter class. Alternatively, you can set the currency when | ||
| formatting a number by using the toCurrency() method. | ||
*/ | ||
'default_currency' => env('NUMERABLE_DEFAULT_CURRENCY', 'USD'), | ||
]; |
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
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,88 @@ | ||
<?php | ||
|
||
use Numerable\Number; | ||
use Numerable\Numerable; | ||
|
||
it('can do a simple format', function () { | ||
expect(Number::toCurrency(22.32)) | ||
->toBeString() | ||
->toEqual('$22.32'); | ||
}); | ||
|
||
it('can do a simple format using helper', function () { | ||
expect(num()->toCurrency(22.32)) | ||
->toBeString() | ||
->toEqual('$22.32'); | ||
}); | ||
|
||
it('can format with default params', function () { | ||
$number = num(new Numerable(12.59)); | ||
$formatted = $number->toCurrency(); | ||
|
||
expect($formatted) | ||
->toBeString() | ||
->toEqual('$12.59'); | ||
}); | ||
|
||
it('can format in other currency', function () { | ||
$number = num(new Numerable(21.21)); | ||
$formatted = $number->toCurrency('BRL'); | ||
|
||
expect($formatted) | ||
->toBeString() | ||
->toEqual('R$21.21'); | ||
}); | ||
|
||
it('can format in other currency in other locale', function () { | ||
$number = num(new Numerable(1_234.42)); | ||
$formatted = $number->toCurrency('BRL', 'pt_BR'); | ||
|
||
expect($formatted) | ||
->toBeString() | ||
->toEqual("R$\u{A0}1.234,42"); | ||
}); | ||
|
||
it('can format using intl code', function () { | ||
$number = num(new Numerable(34.21)); | ||
$formatted = $number->toCurrency(useIntlCode: true); | ||
|
||
expect($formatted) | ||
->toBeString() | ||
->toEqual("USD\u{A0}34.21"); | ||
}); | ||
|
||
it('can format without account', function () { | ||
$number = num(new Numerable(-15.15)); | ||
$formatted = $number->toCurrency(); | ||
|
||
expect($formatted) | ||
->toBeString() | ||
->toEqual("-$15.15"); | ||
}); | ||
|
||
it('can format with account', function () { | ||
$number = num(new Numerable(-15.15)); | ||
$formatted = $number->toCurrency(accounting: true); | ||
|
||
expect($formatted) | ||
->toBeString() | ||
->toEqual("($15.15)"); | ||
}); | ||
|
||
it('can format with 4 places', function () { | ||
$number = num(new Numerable(10.2222)); | ||
$formatted = $number->toCurrency(places: 4); | ||
|
||
expect($formatted) | ||
->toBeString() | ||
->toEqual("$10.2222"); | ||
}); | ||
|
||
it('can format with 4 precision', function () { | ||
$number = num(new Numerable(10.2222)); | ||
$formatted = $number->toCurrency(places: 4, precision: 4); | ||
|
||
expect($formatted) | ||
->toBeString() | ||
->toEqual("$10.22"); | ||
}); |