ASP.NET MVC コントロールヘルプ
Globalize クラス
ファイル
wijmo.js
モジュール
wijmo

数値および日付の書式設定と解析を実装するクラス。

デフォルトでは、Globalize はアメリカ英語カルチャを使用します。カルチャを切り替えるには、該当する**wijmo.culture**ファイルをwijmoファイルの後にインクルードします。

次の例では、Globalize クラスを使用して、さまざまなカルチャの日付、時刻および数値の書式を設定する方法を示しています。

{@sample Core/Globalization/Formatting デモ}

メソッド

メソッド

Static format

format(value: any, format: string, trim?: boolean, truncate?: boolean, defaultPrec?: number): string

数値または日付を書式設定します。

format 関数で使用される書式文字列は、 .NETグローバリゼーションライブラリで使用される書式とほぼ同じです。 使用可能な書式について説明するリンクを以下に示します。

パラメーター
  • value: any

    Number or Date to format (all other types are converted to strings).

  • format: string

    Format string to use when formatting numbers or dates.

  • trim: boolean Optional

    Whether to remove trailing zeros from numeric results.

  • truncate: boolean Optional

    Whether to truncate the numeric values rather than round them.

  • defaultPrec: number Optional

    Precision to use if not specified in the format string.

戻り値
string

Static formatDate

formatDate(value: Date, format: string): string

現在のカルチャを使用して日付を書式設定します。

format パラメータには、.NET形式の カスタム日時形式文字列 と次の追加要素が含まれます。

  • Q, q Calendar quarter.
  • U Fiscal quarter (government).
  • u Fiscal quarter (private sector).
  • EEEE, EEE, EE, E Fiscal year (government).
  • eeee, eee, ee, e Fiscal year (private sector).

For example:

```typescript import { Globalize } from '@grapecity/wijmo'; let dt = new Date(2015, 9, 1); // 2015年10月1日 console.log('result', Globalize.format(dt, '"FY"EEEE"Q"U') + ' (US culture)'); **result** FY2016Q1 (US culture) ```

日本の文化で定義されているような複雑な時代に対処するための別の追加機能があります。

  • ggg Era name (e.g. '??????', '??????', '??????', or '??????').
  • gg Era initial (e.g. '???', '???', '???', or '???').
  • g Era symbol (e.g. 'H', 'S', 'T', or 'M').

{@sample Core/Globalization/Formatting/purejs デモ}

パラメーター
  • value: Date

    Number or Date to format.

  • format: string

    .NET-style Date format string.

戻り値
string

Static formatNumber

formatNumber(value: number, format: string, trim?: boolean, truncate?: boolean, defaultPrec?: number): string

現在のカルチャを使用して数値を書式設定します。

formatNumber メソッドは、すべての .NET形式の 標準の数値書式指定文字列 を受け入れ、 スケーリング、プレフィックス、サフィックス、およびカスタム通貨記号をサポートします。

数値書式文字列の形式はAxxssccです。

  • A is a single alphabetic character called the format specifier (described below).
  • xx is an optional integer called the precision specifier. The precision specifier affects the number of digits in the result.
  • ss is an optional string used to scale the number. If provided, it must consist of commas. The number is divided by 1000 for each comma specified.
  • cc is an optional string used to override the currency symbol when formatting currency values. This is useful when formatting currency values for cultures different than the current default (for example, when formatting Euro or Yen values in applications that use the English culture).

次の表に、標準の数値書式指定子と、デフォルトカルチャを使用した場合の出力サンプルを示します。

c 通貨: formatNumber(1234, 'c') => '$1,234.00'
d 10進数(整数): formatNumber(-1234, 'd6') => '-001234'
e 科学表記(小文字の「e」): formatNumber(123.456, 'e6') => '1.234560e+2' E 科学表記(大文字の「e」): formatNumber(123.456, 'E6') => '1.234560E+2' f 固定小数点: formatNumber(1234.5, 'f2') => '1234.50'
F 固定小数点(桁区切り記号付き): formatNumber(1234.5, 'F2') => '1,234.50'
g 汎用(末尾のゼロなし): formatNumber(1234.50, 'g2') => '1234.5'
G 汎用(末尾のゼロなし、 桁区切り記号): formatNumber(1234.5, 'G2') => '1,234.5'
n 数値: formatNumber(1234.5, 'n2') => '1,234.50'
p Percent: formatNumber(0.1234, 'p2') => '12.34%' P パーセント(千単位の区切り文字なし): formatNumber(12.34, 'P2') => '1234%' r ウンド トリップ (g15と同じ): formatNumber(0.1234, 'r') => '0.1234' x 16進数(整数): formatNumber(1234, 'x6') => '0004d2'

単位変更指定子は、大きな値をチャートに表示する場合に特に便利です。たとえば、 次のマークアップは、人口とGDPをプロットするチャートを作成します。 生のデータでは、 人口は人数そのもの、GDPは100万単位です。 軸の書式設定で指定された単位変更に基づいて、人口は100万単位、GDPは兆単位で表示されます。

```typescript import { FlexChart} from '@grapecity/wijmo.chart'; new FlexChart('#theChart', { itemsSource: countriesGDP, bindingX: 'pop', chartType: 'Scatter', series: [ { name: 'GDP', binding: 'gdp' } ], axisX: { title: 'Population (millions)' format: 'n0,,' }, axisY: { title: 'GDP (US$ trillions)' format: 'c0,,' } }); ```

書式文字列には、出力に追加される定数の接頭辞と接尾辞の文字列を含めることもできます。存在する場合、接頭辞と接尾辞は、フォーマット文字列の先頭と末尾に 二重引用符で囲まれた文字列として指定されます。

```typescript import { Globalize } from '@grapecity/wijmo'; console.log(Globalize.formatNumber(value, '"thousands: "c3," k"')); console.log(Globalize.formatNumber(value, '"millions: "c1,," M"')); ```

パラメーター
  • value: number

    Number to format.

  • format: string

    .NET-style standard numeric format string (e.g. 'n2', 'c4', 'p0', 'g2', 'd2').

  • trim: boolean Optional

    Whether to remove trailing zeros from the result.

  • truncate: boolean Optional

    Whether to truncate the value rather than round it.

  • defaultPrec: number Optional

    Precision to use if not specified in the format string.

戻り値
string

Static getFirstDayOfWeek

getFirstDayOfWeek(): number

現在のカルチャに従って週の最初の曜日を取得します。

返される値は0(日曜日)~6(土曜日)です。

戻り値
number

Static getNumberDecimalSeparator

getNumberDecimalSeparator(): string

数値の小数点記号として使用される記号を取得します。

戻り値
string

Static parseDate

parseDate(value: string, format: string, refDate?: Date): Date

文字列を日付に解析します。

2桁の年は、カレンダーの twoDigitYearMax プロパティの値に基づいて、完全な年に変換されます。 デフォルトでは、このプロパティは2029に設定されています。 つまり、2桁の30〜99の値は19xxになり、0〜29の値は20xxになります。

このしきい値は、カレンダーに新しい値を割り当てて変更できます。 次に例を示します。

// カレンダーを取得します
var cal = wijmo.culture.Globalize.calendar;

// デフォルトのしきい値は2029なので、"30"は1930と解析されます
cal.twoDigitYearMax = 2029;
var d1 = wijmo.Globalize.parseDate('30/12', 'yy/MM'); // 1930年12月
// しきい値を2100に変更すると、すべての値が20**と解析されます
cal.twoDigitYearMax = 2100;
var d2 = wijmo.Globalize.parseDate('30/12', 'yy/MM'); // 2030年12月
パラメーター
  • value: string

    String to convert to a Date.

  • format: string

    Format string used to parse the date.

  • refDate: Date Optional

    Date to use as a reference in case date or time parts are not specified in the format string (e.g. format = 'MM/dd').

戻り値
Date

Static parseFloat

parseFloat(value: string, format?: string): number

文字列を浮動小数点数に解析します。

パラメーター
  • value: string

    String to convert to a number.

  • format: string Optional

    Format to use when parsing the number.

戻り値
number

Static parseInt

parseInt(value: string, format?: string): number

文字列を整数に解析します。

パラメーター
  • value: string

    String to convert to an integer.

  • format: string Optional

    Format to use when parsing the number.

戻り値
number