SYNCER

SYNCER

localeconv() - 現在のロケールに基づく数値のフォーマット情報を取得する

公開日:

localeconvは、現在のロケール情報に基づいた、数値の各種フォーマット情報を取得する関数です。

構文

array localeconv ( void )

パラメータ

引数はありません。

返り値

array

数値のフォーマット情報を含む配列。配列の各キーは下記の意味を持つ。

decimal_point
小数点の文字。
thousands_sep
千ごとの区切り文字。
grouping
数値集合を有する配列。
int_curr_symbol
国際的な通貨記号。USDなど。
currency_symbol
ローカルな通貨記号。$など。
mon_decimal_point
通貨用の千ごとの区切り文字。
mon_thousands_sep
千ごとの区切り文字。
mon_grouping
通貨集合を有する配列。
positive_sign
正の値を表す記号。
negative_sign
負の値を表す記号。
int_frac_digits
国際分割桁。
frac_digits
ローカルな分割桁。
p_cs_precedes
currency_symbolが正の値を前に置く場合にTRUE、後に置く場合にFALSE
p_sep_by_space
正の値とcurrency_symbolの間に1文字分の空白がある場合にTRUE、ない場合にFALSE
n_cs_precedes
currency_symbolが負の値を前に置く場合にTRUE、後に置く場合にFALSE
n_sep_by_space
負の値とcurrency_symbolの間に1文字分の空白がある場合にTRUE、ない場合にFALSE
p_sign_posn
0
量、通貨記号を括る括弧。
1
量、通貨記号の前に置く符号文字列。
2
量、通貨記号の後に置く符号文字列。
3
通貨記号の直前に置く符号文字列。
4
通貨記号の直後に置く符号文字列。
n_sign_posn
0
量、通貨記号を括る括弧。
1
量、通貨記号の前に置く符号文字列。
2
量、通貨記号の後に置く符号文字列。
3
通貨記号の直前に置く符号文字列。
4
通貨記号の直後に置く符号文字列。

サンプルコード

数値のフォーマット情報を取得する

現在のロケールでは数値がどのようにフォーマットされるか、その変換方法の情報を含んだ配列を取得します。日本の場合は利用されない項目が多いです。

php

<?php
	// 実行
	$result = localeconv() ;

	// 結果
	var_dump( $result ) ;

結果 (出力内容) - PHP7.0.21

array(18) {
  ["decimal_point"]=>
  string(1) "."
  ["thousands_sep"]=>
  string(0) ""
  ["int_curr_symbol"]=>
  string(0) ""
  ["currency_symbol"]=>
  string(0) ""
  ["mon_decimal_point"]=>
  string(0) ""
  ["mon_thousands_sep"]=>
  string(0) ""
  ["positive_sign"]=>
  string(0) ""
  ["negative_sign"]=>
  string(0) ""
  ["int_frac_digits"]=>
  int(127)
  ["frac_digits"]=>
  int(127)
  ["p_cs_precedes"]=>
  int(127)
  ["p_sep_by_space"]=>
  int(127)
  ["n_cs_precedes"]=>
  int(127)
  ["n_sep_by_space"]=>
  int(127)
  ["p_sign_posn"]=>
  int(127)
  ["n_sign_posn"]=>
  int(127)
  ["grouping"]=>
  array(0) {
  }
  ["mon_grouping"]=>
  array(0) {
  }
}

オランダの場合

ロケールをオランダに変えてみると、フォーマットの内容も変わります。

php

<?php
	// ロケールをオランダに変更
	setlocale( LC_ALL, 'nl_NL' ) ;

	// 実行
	$result = localeconv() ;

	// 結果
	var_dump( $result ) ;

結果 (出力内容) - PHP7.0.21

array(18) {
  ["decimal_point"]=>
  string(1) ","
  ["thousands_sep"]=>
  string(0) ""
  ["int_curr_symbol"]=>
  string(4) "EUR "
  ["currency_symbol"]=>
  string(3) "EUR"
  ["mon_decimal_point"]=>
  string(1) ","
  ["mon_thousands_sep"]=>
  string(1) " "
  ["positive_sign"]=>
  string(0) ""
  ["negative_sign"]=>
  string(1) "-"
  ["int_frac_digits"]=>
  int(2)
  ["frac_digits"]=>
  int(2)
  ["p_cs_precedes"]=>
  int(1)
  ["p_sep_by_space"]=>
  int(1)
  ["n_cs_precedes"]=>
  int(1)
  ["n_sep_by_space"]=>
  int(1)
  ["p_sign_posn"]=>
  int(1)
  ["n_sign_posn"]=>
  int(2)
  ["grouping"]=>
  array(0) {
  }
  ["mon_grouping"]=>
  array(2) {
    [0]=>
    int(3)
    [1]=>
    int(3)
  }
}

アメリカの場合

もう1つ、今度はアメリカの例を確認しておきましょう。

php

<?php
	// ロケールをアメリカに変更
	setlocale( LC_ALL, 'en_US' ) ;

	// 実行
	$result = localeconv() ;

	// 結果
	var_dump( $result ) ;

結果 (出力内容) - PHP7.0.21

array(18) {
  ["decimal_point"]=>
  string(1) "."
  ["thousands_sep"]=>
  string(1) ","
  ["int_curr_symbol"]=>
  string(4) "USD "
  ["currency_symbol"]=>
  string(1) "$"
  ["mon_decimal_point"]=>
  string(1) "."
  ["mon_thousands_sep"]=>
  string(1) ","
  ["positive_sign"]=>
  string(0) ""
  ["negative_sign"]=>
  string(1) "-"
  ["int_frac_digits"]=>
  int(2)
  ["frac_digits"]=>
  int(2)
  ["p_cs_precedes"]=>
  int(1)
  ["p_sep_by_space"]=>
  int(0)
  ["n_cs_precedes"]=>
  int(1)
  ["n_sep_by_space"]=>
  int(0)
  ["p_sign_posn"]=>
  int(1)
  ["n_sign_posn"]=>
  int(1)
  ["grouping"]=>
  array(2) {
    [0]=>
    int(3)
    [1]=>
    int(3)
  }
  ["mon_grouping"]=>
  array(2) {
    [0]=>
    int(3)
    [1]=>
    int(3)
  }
}

サンドボックス

ソースコードを編集してlocaleconv()の挙動を確認して下さい。

Array
(
    [decimal_point] => .
    [thousands_sep] => 
    [int_curr_symbol] => 
    [currency_symbol] => 
    [mon_decimal_point] => 
    [mon_thousands_sep] => 
    [positive_sign] => 
    [negative_sign] => 
    [int_frac_digits] => 127
    [frac_digits] => 127
    [p_cs_precedes] => 127
    [p_sep_by_space] => 127
    [n_cs_precedes] => 127
    [n_sep_by_space] => 127
    [p_sign_posn] => 127
    [n_sign_posn] => 127
    [grouping] => Array
        (
        )

    [mon_grouping] => Array
        (
        )

)

参考リンク

  • PHP - 公式マニュアル。