Download the PHP package cable8mm/n-format without Composer

On this page you can find all versions of the php package cable8mm/n-format. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package n-format

N-Format

code-style run-tests Packagist Version Packagist Downloads Packagist License

Laravel 애플리케이션에서 숫자, 통화, 퍼센트, 서수 표현을 일관되게 다루기 위한 PHP 패키지입니다. PHP의 NumberFormatter를 확장한 NFormat API와 함께 Laravel 서비스 프로바이더, 설정 파일, Eloquent 캐스트, 불변 값 객체를 제공합니다.

v2부터 N-Format은 NFormat 클래스 하나만 제공하던 래퍼에서 Laravel 통합을 포함하는 패키지로 확장되었습니다.

요구 사항

설치

Laravel의 패키지 자동 검색을 지원하므로 별도로 서비스 프로바이더를 등록할 필요가 없습니다.

설정

기본 설정은 한국어·대한민국 원화입니다.

설정 파일이 필요하면 애플리케이션으로 게시합니다.

게시한 설정은 모든 NFormat 메서드와 값 객체의 기본값으로 사용됩니다. 특정 호출에서 로케일이나 통화를 직접 전달하여 기본값을 덮어쓸 수도 있습니다.

기본 사용법

percent()는 입력값에 100을 곱하고, rawPercent()는 입력값을 100으로 나눈 뒤 퍼센트로 표시합니다.

PHP 8.2 이상에서는 파라미터 이름을 지정하는 named arguments도 사용할 수 있습니다. 긴 호출에서 각 값의 의미를 명확하게 표현할 수 있습니다.

메서드 파라미터 이름은 공개 API의 일부이므로, named arguments를 사용하는 경우 파라미터 이름 변경에 주의해야 합니다.

호출별로 로케일과 통화를 지정할 수 있습니다.

currency()의 두 번째 인자는 0 또는 null일 때 사용할 대체 문자열입니다. 세 번째와 네 번째 인자가 각각 로케일과 통화입니다.

가격 반올림

price()는 지정한 자릿수로 반올림하고, smartPrice()는 통화 드라이버의 규칙에 따라 자릿수별로 반올림합니다.

기본 KRW 규칙은 다음과 같습니다.

Eloquent 캐스트

v2는 Eloquent 속성을 불변 값 객체로 변환하는 두 가지 캐스트를 제공합니다.

읽을 때는 값 객체가 반환되고, 저장할 때는 통화 기호와 천 단위 구분자를 제거한 숫자만 데이터베이스에 저장됩니다.

currency()는 금액이 0이어도 통화 형식으로 표시합니다. 무료 상품처럼 0원을 별도 문구로 표시하려면 display()를 사용합니다.

기본 번역은 한국어 무료, 영어 Free, 일본어 無料이며, AsCurrency에 지정한 로케일을 기준으로 선택합니다. 번역 파일은 다음 명령으로 게시할 수 있습니다.

번역 키는 n-format::messages.free입니다.

Number는 기본적으로 천 단위 구분자를 사용해 출력합니다.

두 값 객체는 Stringable, JsonSerializable을 구현합니다. 문자열로 출력하면 포맷된 값을 사용하고, JSON으로 직렬화하면 원시 숫자를 사용합니다.

Blade에서도 그대로 사용할 수 있습니다.

숫자·통화 캐스트는 숫자와 포맷된 숫자 문자열을 저장할 수 있습니다. null, 빈 문자열, 숫자로 변환할 수 없는 값은 null로 저장되거나 읽힙니다.

드라이버 확장

로케일별 서수 표현과 통화별 가격 규칙은 드라이버로 분리되어 있습니다. 다음 인터페이스를 구현한 뒤 등록하면 지원 범위를 확장할 수 있습니다.

통화 드라이버는 currencySpellOut()과 roundDigits()를 구현합니다.

기본 제공 드라이버는 ko_KR 서수 표현과 KRW 통화 규칙입니다. 등록되지 않은 드라이버를 요청하면 ordinalSpellOut()과 currencySpellOut()은 NumberFormatter의 기본 결과를 반환합니다.

API

메서드 설명
spellOut(int, ?string) 숫자를 단어로 변환
ordinalSpellOut(int, ?string) 서수 표현
currency(int\|float\|null, string, ?string, ?string) 통화 포맷
currencySpellOut(int\|float, ?string, ?string) 통화와 단어를 함께 표시
decimal(int\|float\|null, string, ?string) 천 단위 구분자 포맷
percent(int\|float, ?string) 100을 곱한 퍼센트
rawPercent(int\|float, ?string) 100으로 나눈 퍼센트
price(int\|float, ?int) 지정 자릿수 반올림
smartPrice(int\|float, ?string) 통화 규칙에 따른 반올림
registerOrdinal(string, OrdinalDriver) 로케일 드라이버 등록
registerCurrency(string, CurrencyDriver) 통화 드라이버 등록

개발

라이선스

N-Format은 MIT 라이선스로 제공됩니다.


All versions of n-format with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
ext-intl Version *
illuminate/contracts Version ^12.0|^13.0
illuminate/database Version ^12.0|^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package cable8mm/n-format contains the following files

Loading the files please wait ...