共用方式為


PercentFormatter 類別

定義

格式化和剖析百分比。

public ref class PercentFormatter sealed : INumberFormatter, INumberFormatter2, INumberFormatterOptions, INumberParser, INumberRounderOption, ISignedZeroOption, ISignificantDigitsOption
/// [Windows.Foundation.Metadata.Activatable(65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.Activatable(Windows.Globalization.NumberFormatting.IPercentFormatterFactory, 65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class PercentFormatter final : INumberFormatter, INumberFormatter2, INumberFormatterOptions, INumberParser, INumberRounderOption, ISignedZeroOption, ISignificantDigitsOption
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.Activatable(Windows.Globalization.NumberFormatting.IPercentFormatterFactory, 65536, "Windows.Foundation.UniversalApiContract")]
class PercentFormatter final : INumberFormatter, INumberFormatter2, INumberFormatterOptions, INumberParser, INumberRounderOption, ISignedZeroOption, ISignificantDigitsOption
[Windows.Foundation.Metadata.Activatable(65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.Activatable(typeof(Windows.Globalization.NumberFormatting.IPercentFormatterFactory), 65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class PercentFormatter : INumberFormatter, INumberFormatter2, INumberFormatterOptions, INumberParser, INumberRounderOption, ISignedZeroOption, ISignificantDigitsOption
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.Activatable(typeof(Windows.Globalization.NumberFormatting.IPercentFormatterFactory), 65536, "Windows.Foundation.UniversalApiContract")]
public sealed class PercentFormatter : INumberFormatter, INumberFormatter2, INumberFormatterOptions, INumberParser, INumberRounderOption, ISignedZeroOption, ISignificantDigitsOption
function PercentFormatter(languages, geographicRegion)
Public NotInheritable Class PercentFormatter
Implements INumberFormatter, INumberFormatter2, INumberFormatterOptions, INumberParser, INumberRounderOption, ISignedZeroOption, ISignificantDigitsOption
繼承
Object Platform::Object IInspectable PercentFormatter
屬性
實作

Windows 需求

裝置系列
Windows 10 (已於 10.0.10240.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)

範例

// This scenario uses the Windows.Globalization.NumberFormatting.PercentFormatter and
// the Windows.Globalization.NumberFormatting.PermilleFormatter classes to format numbers
// as a percent or a permille.

//using System.Text;
//using Windows.Globalization.NumberFormatting;

StringBuilder sb = new StringBuilder();

// Create numbers to format.
double randomNumber = new Random().NextDouble();
ulong fixedNumber = 500;

// Create percent formatters.
PercentFormatter defaultPercentFormatter = new PercentFormatter();
PercentFormatter languagePercentFormatter = new PercentFormatter(new[] { "fr-FR" }, "ZZ");

// Create permille formatters.
PermilleFormatter defaultPermilleFormatter = new PermilleFormatter();
PermilleFormatter languagePermilleFormatter = new PermilleFormatter(new[] { "ar" }, "ZZ");

// Format random numbers as percent or permille.
sb.AppendLine("Random number: " + randomNumber);
sb.AppendLine("Percent formatted: " + defaultPercentFormatter.Format(randomNumber));
sb.AppendLine("Permille formatted: " + defaultPermilleFormatter.Format(randomNumber));
sb.AppendLine();
sb.AppendLine("Language-specific percent formatted: " + languagePercentFormatter.Format(randomNumber));
sb.AppendLine("Language-specific permille formatted: " + languagePermilleFormatter.Format(randomNumber));
sb.AppendLine();
sb.AppendLine("Fixed number: " + fixedNumber);

// Format fixed number with grouping.
defaultPercentFormatter.IsGrouped = true;
sb.AppendLine("Percent formatted (grouped): " + defaultPercentFormatter.Format(fixedNumber));

//Format with grouping using French language.
languagePercentFormatter.IsGrouped = true;
sb.AppendLine("Percent formatted (grouped as fr-FR): " + defaultPercentFormatter.Format(fixedNumber));

// Format with no fraction digits.
defaultPercentFormatter.FractionDigits = 0;
sb.AppendLine("Percent formatted (no fractional digits): " + defaultPercentFormatter.Format(fixedNumber));

// Format always with a decimal point.
defaultPercentFormatter.IsDecimalPointAlwaysDisplayed = true;
sb.AppendLine("Percent formatted (always with a decimal point): " + defaultPercentFormatter.Format(fixedNumber));

備註

注意

如果您的 app 會將此類別中使用的語言標籤傳遞給任何 國家語言支援 函式,則必須先呼叫 ResolveLocaleName來轉換標籤。

建構函式

PercentFormatter()

建立 PercentFormatter 物件,並將其初始化為預設值。

PercentFormatter(IIterable<String>, String)

建立由語言清單和地理區域初始化的 PercentFormatter 物件。

屬性

FractionDigits

取得或設定要針對百分比分數部分顯示的最小位數。

GeographicRegion

取得格式化和剖析百分比時所使用的區域。

IntegerDigits

取得或設定要針對百分比整數部分顯示的最小位數。

IsDecimalPointAlwaysDisplayed

取得或設定是否應該一律顯示百分比的小數點。

IsGrouped

取得或設定是否應該將百分比的整數部分分組。

IsZeroSigned

取得或設定 -0 是否格式化為 「-0」 或 「0」。

Languages

取得格式化和剖析百分比時所使用的語言識別項優先順序清單。

NumberRounder

取得或設定格式化百分比時要使用的目前四捨五入策略。

NumeralSystem

取得或設定用來格式化和剖析百分比的編號系統。

ResolvedGeographicRegion

取得最近用來格式化或剖析百分比值的地理區域。

ResolvedLanguage

取得最近用來格式化或剖析百分比值的語言。

SignificantDigits

取得或設定當百分比格式化時,目前的填補為有效位數。

方法

Format(Double)

傳回 Double 百分比的字串表示。

Format(Int64)

傳回 Int64 百分比的字串表示。

Format(UInt64)

傳回 UInt64 百分比的字串表示。

FormatDouble(Double)

傳回 Double 百分比的字串表示。

FormatInt(Int64)

傳回 Int64 百分比的字串表示。

FormatUInt(UInt64)

傳回 UInt64 百分比的字串表示。

ParseDouble(String)

嘗試剖析 Double 百分比的字串表示。

ParseInt(String)

嘗試剖析整數百分比的字串表示。

ParseUInt(String)

嘗試剖析不帶正負號整數百分比的字串表示。

適用於

另請參閱