PercentFormatter, classe

PercentFormatter Class

Formate et analyse les pourcentages.

Syntaxe


var percentFormatter = new Windows.Globalization.NumberFormatting.PercentFormatter(iIterable(String));
var percentFormatter = new Windows.Globalization.NumberFormatting.PercentFormatter();

Attributs

[DualApiPartition()]
[MarshalingBehavior(Agile)]
[Threading(Both)]
[Version(0x06020000)]

Membres

PercentFormatterClasse possède ces types de membres :

Constructeurs

PercentFormatterClasse possède ces constructeurs.

ConstructeurDescription
PercentFormatter() Creates a PercentFormatter object and initializes it to default values.
PercentFormatter(IIterable(String), String) Creates a PercentFormatter object initialized by a language list and a geographic region.

 

Méthodes

The PercentFormatter Classe a les méthodes suivantes. Avec C#, Visual Basic et C++, elle hérite également des méthodes de Object Classe.

MéthodeDescription
Format(Double) Returns a string representation of a Double percentage.
Format(Int64) Returns a string representation of an Int64 percentage.
Format(UInt64) Returns a string representation of a UInt64 percentage.
FormatDouble Returns a string representation of a Double percentage.
FormatInt Returns a string representation of an Int64 percentage.
FormatUInt Returns a string representation of a UInt64 percentage.
ParseDouble Attempts to parse a string representation of a Double percentage.
ParseInt Attempts to parse a string representation of an integer percentage.
ParseUInt Attempts to parse a string representation of an unsigned integer percentage.

 

Propriétés

Le PercentFormatterClasse a les propriétés suivantes.

PropriétéType d'accèsDescription

FractionDigits

Lecture/écritureGets or sets the minimum number of digits to display for the fraction part of the percentage.

GeographicRegion

En lecture seuleGets the region that is used when formatting and parsing percentages.

IntegerDigits

Lecture/écritureGets or sets the minimum number of digits to display for the integer part of the percentage.

IsDecimalPointAlwaysDisplayed

Lecture/écritureGets or sets whether the decimal point of the percentage should always be displayed.

IsGrouped

Lecture/écritureGets or sets whether the integer part of the percentage should be grouped.

IsZeroSigned

Lecture/écritureGets or sets whether -0 is formatted as -0 or 0.

Languages

En lecture seuleGets the priority list of language identifiers that is used when formatting and parsing percentages.

NumberRounder

Lecture/écritureGets or sets the current rounding strategy to be used when formatting percents.

NumeralSystem

Lecture/écritureGets or sets the numbering system that is used to format and parse percentages.

ResolvedGeographicRegion

En lecture seuleGets the geographic region that was most recently used to format or parse percent values.

ResolvedLanguage

En lecture seuleGets the language that was most recently used to format or parse percent values.

SignificantDigits

Lecture/écritureGets or sets the current padding to significant digits when a percent is formatted.

 

Remarques

Remarque  Si votre application passe les balises de langue utilisées cette classe aux fonctions NLS (National Language Support), elle doit d'abord convertir les balises en appelant ResolveLocaleName.

Exemples


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

// Create formatters initialized using the current user's preference settings.
var percentFormat = new Windows.Globalization.NumberFormatting.PercentFormatter();
var permilleFormat = new Windows.Globalization.NumberFormatting.PermilleFormatter();

// Make a random number.
var randomNumber = Math.random();

// Format with current user preferences.
var percent = percentFormat.format(randomNumber);
var permille = permilleFormat.format(randomNumber);

// Get a fixed number.
var fixedNumber = 500;

// Format with grouping using default.
var percentFormat1 = new Windows.Globalization.NumberFormatting.PercentFormatter();
percentFormat1.isGrouped = true;
var percent1 = percentFormat1.format(fixedNumber);

// Format with grouping using French.
var percentFormatFR = new Windows.Globalization.NumberFormatting.PercentFormatter(["fr-FR"], "FR");
percentFormatFR.isGrouped = true;
var percentFR = percentFormatFR.format(fixedNumber);

// Format with no fractional digits using default.
var percentFormat2 = new Windows.Globalization.NumberFormatting.PercentFormatter();
percentFormat2.fractionDigits = 0;
var percent2 = percentFormat2.format(fixedNumber);

// Format always with a decimal point.
var percentFormat3 = new Windows.Globalization.NumberFormatting.PercentFormatter();
percentFormat3.isDecimalPointAlwaysDisplayed = true;
percentFormat3.fractionDigits = 0;
var percent3 = percentFormat3.format(fixedNumber);

// Display the results.
var results = "Random number (" + randomNumber + ")\n" +
              "Percent formatted: " + percent + "\n" +
              "Permille formatted: " + permille + "\n\n" +
              "Fixed number (" + fixedNumber + ")\n" +
              "Percent formatted (grouped): " + percent1 + "\n" +
              "Percent formatted (grouped as fr-FR): " + percentFR + "\n" +
              "Percent formatted (no fractional digits): " + percent2 + "\n" +
              "Percent formatted (always with a decimal point): " + percent3;

Conditions requises

Client minimal pris en charge

Windows 8 [Applications Windows Store, applications de bureau]

Serveur minimal pris en charge

Windows Server 2012 [Applications Windows Store, applications de bureau]

Espace de noms

Windows.Globalization.NumberFormatting
Windows::Globalization::NumberFormatting [C++]

Métadonnées

Windows.winmd

Voir aussi

Exemple d'analyse et de mise en forme de nombres
Object
INumberFormatterOptions
INumberFormatter
INumberFormatter2
INumberParser
ISignificantDigitsOption
INumberRounderOption

 

 

Afficher:
© 2017 Microsoft