PercentFormatter Classe

Definição

Formata e analisa percentuais.

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
Herança
Object Platform::Object IInspectable PercentFormatter
Atributos
Implementações

Requisitos do Windows

Família de dispositivos
Windows 10 (introduzida na 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduzida na v1.0)

Exemplos

// 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));

Comentários

Observação

Se seu aplicativo passar marcas de idioma usadas nessa classe para qualquer função de Suporte à Linguagem Nacional , ele deverá primeiro converter as marcas chamando ResolveLocaleName.

Construtores

PercentFormatter()

Cria um objeto PercentFormatter e o inicializa para valores padrão.

PercentFormatter(IIterable<String>, String)

Cria um objeto PercentFormatter inicializado por uma lista de idiomas e uma região geográfica.

Propriedades

FractionDigits

Obtém ou define o número mínimo de dígitos a serem exibidos para a parte de fração do percentual.

GeographicRegion

Obtém a região usada ao formatar e analisar percentuais.

IntegerDigits

Obtém ou define o número mínimo de dígitos a serem exibidos para a parte inteira da porcentagem.

IsDecimalPointAlwaysDisplayed

Obtém ou define se o ponto decimal da porcentagem sempre deve ser exibido.

IsGrouped

Obtém ou define se a parte inteira da porcentagem deve ser agrupada.

IsZeroSigned

Obtém ou define se -0 está formatado como "-0" ou "0".

Languages

Obtém a lista de prioridades de identificadores de idioma usados ao formatar e analisar percentuais.

NumberRounder

Obtém ou define a estratégia de arredondamento atual a ser usada ao formatar porcentagens.

NumeralSystem

Obtém ou define o sistema de numeração usado para formatar e analisar porcentagens.

ResolvedGeographicRegion

Obtém a região geográfica que foi usada mais recentemente para formatar ou analisar valores percentuais.

ResolvedLanguage

Obtém o idioma que foi usado mais recentemente para formatar ou analisar valores percentuais.

SignificantDigits

Obtém ou define o preenchimento atual como dígitos significativos quando uma porcentagem é formatada.

Métodos

Format(Double)

Retorna uma representação de cadeia de caracteres de uma porcentagem Double .

Format(Int64)

Retorna uma representação de cadeia de caracteres de uma porcentagem Int64 .

Format(UInt64)

Retorna uma representação de cadeia de caracteres de uma porcentagem UInt64 .

FormatDouble(Double)

Retorna uma representação de cadeia de caracteres de uma porcentagem Double .

FormatInt(Int64)

Retorna uma representação de cadeia de caracteres de uma porcentagem Int64 .

FormatUInt(UInt64)

Retorna uma representação de cadeia de caracteres de uma porcentagem UInt64 .

ParseDouble(String)

Tenta analisar uma representação de cadeia de caracteres de uma porcentagem Double .

ParseInt(String)

Tenta analisar uma representação de cadeia de caracteres de um percentual inteiro.

ParseUInt(String)

Tenta analisar uma representação de cadeia de caracteres de uma porcentagem de inteiro sem sinal.

Aplica-se a

Confira também