Share via


NumberFormatInfo.PercentDecimalDigits プロパティ

パーセント値で使用する小数点以下の桁数を示します。

Public Property PercentDecimalDigits As Integer
[C#]
public int PercentDecimalDigits {get; set;}
[C++]
public: __property int get_PercentDecimalDigits();public: __property void set_PercentDecimalDigits(int);
[JScript]
public function get PercentDecimalDigits() : int;public function set PercentDecimalDigits(int);

プロパティ値

パーセント値で使用する小数点以下の桁数。 InvariantInfo の既定値は 2 です。

例外

例外の種類 条件
ArgumentOutOfRangeException プロパティが 0 より小さいか、99 より大きい値に設定されています。
InvalidOperationException プロパティが設定されていますが、 NumberFormatInfo が読み取り専用です。

使用例

[Visual Basic, C#, C++] PercentDecimalDigits プロパティの変更による影響を次のコード例に示します。

 
Imports System
Imports System.Globalization

Class NumberFormatInfoSample

   Public Shared Sub Main()

      ' Gets a NumberFormatInfo associated with the en-US culture.
      Dim nfi As NumberFormatInfo = New CultureInfo("en-US", False).NumberFormat

      ' Displays a negative value with the default number of decimal digits (2).
      Dim myInt As [Double] = 0.1234
      Console.WriteLine(myInt.ToString("P", nfi))

      ' Displays the same value with four decimal digits.
      nfi.PercentDecimalDigits = 4
      Console.WriteLine(myInt.ToString("P", nfi))

   End Sub 'Main 

End Class 'NumberFormatInfoSample



'This code produces the following output.

'

'12.34 %

'12.3400 %



[C#] 
using System;
using System.Globalization;

class NumberFormatInfoSample {

   public static void Main() {

      // Gets a NumberFormatInfo associated with the en-US culture.
      NumberFormatInfo nfi = new CultureInfo( "en-US", false ).NumberFormat;

      // Displays a negative value with the default number of decimal digits (2).
      Double myInt = 0.1234;
      Console.WriteLine( myInt.ToString( "P", nfi ) );

      // Displays the same value with four decimal digits.
      nfi.PercentDecimalDigits = 4;
      Console.WriteLine( myInt.ToString( "P", nfi ) );

   }
}


/* 
This code produces the following output.

12.34 %
12.3400 %
*/
   

[C++] 
#using <mscorlib.dll>
using namespace System;
using namespace System::Globalization;

int main()
{
   // Gets a NumberFormatInfo associated with the en-US culture.
   CultureInfo * MyCI = new CultureInfo(S"en-US", false);
   NumberFormatInfo* nfi = MyCI -> NumberFormat;

   // Displays a negative value with the default number of decimal digits (2).
   Double myInt = 0.1234;
   Console::WriteLine(myInt.ToString(S"P", nfi));

   // Displays the same value with four decimal digits.
   nfi -> PercentDecimalDigits = 4;
   Console::WriteLine(myInt.ToString(S"P", nfi));
}
/*
This code produces the following output.
12.34 %
12.3400 %
*/

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard

参照

NumberFormatInfo クラス | NumberFormatInfo メンバ | System.Globalization 名前空間 | PercentDecimalSeparator | PercentGroupSeparator | PercentGroupSizes | PercentSymbol | PercentNegativePattern | PercentPositivePattern | CurrencyDecimalDigits | NumberDecimalDigits