PercentFormatter PercentFormatter PercentFormatter PercentFormatter PercentFormatter Class

Definition

Formats and parses percentages.

public : sealed class PercentFormatter : INumberFormatter, INumberFormatter2, INumberFormatterOptions, INumberParser, INumberRounderOption, ISignedZeroOption, ISignificantDigitsOption
struct winrt::Windows::Globalization::NumberFormatting::PercentFormatter : INumberFormatter, INumberFormatter2, INumberFormatterOptions, INumberParser, INumberRounderOption, ISignedZeroOption, ISignificantDigitsOption
public sealed class PercentFormatter : INumberFormatter, INumberFormatter2, INumberFormatterOptions, INumberParser, INumberRounderOption, ISignedZeroOption, ISignificantDigitsOption
Public NotInheritable Class PercentFormatter Implements INumberFormatter, INumberFormatter2, INumberFormatterOptions, INumberParser, INumberRounderOption, ISignedZeroOption, ISignificantDigitsOption
var percentFormatter = new percentFormatter();
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Examples

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

Remarks

Note

If your app passes language tags used in this class to any National Language Support functions, it must first convert the tags by calling ResolveLocaleName.

Constructors

PercentFormatter() PercentFormatter() PercentFormatter() PercentFormatter() PercentFormatter()

Creates a PercentFormatter object and initializes it to default values.

PercentFormatter(IIterable<String>, String) PercentFormatter(IIterable<String>, String) PercentFormatter(IIterable<String>, String) PercentFormatter(IIterable<String>, String) PercentFormatter(IIterable<String>, String)

Creates a PercentFormatter object initialized by a language list and a geographic region.

Properties

FractionDigits FractionDigits FractionDigits FractionDigits FractionDigits

Gets or sets the minimum number of digits to display for the fraction part of the percentage.

GeographicRegion GeographicRegion GeographicRegion GeographicRegion GeographicRegion

Gets the region that is used when formatting and parsing percentages.

IntegerDigits IntegerDigits IntegerDigits IntegerDigits IntegerDigits

Gets or sets the minimum number of digits to display for the integer part of the percentage.

IsDecimalPointAlwaysDisplayed IsDecimalPointAlwaysDisplayed IsDecimalPointAlwaysDisplayed IsDecimalPointAlwaysDisplayed IsDecimalPointAlwaysDisplayed

Gets or sets whether the decimal point of the percentage should always be displayed.

IsGrouped IsGrouped IsGrouped IsGrouped IsGrouped

Gets or sets whether the integer part of the percentage should be grouped.

IsZeroSigned IsZeroSigned IsZeroSigned IsZeroSigned IsZeroSigned

Gets or sets whether -0 is formatted as "-0" or "0".

Languages Languages Languages Languages Languages

Gets the priority list of language identifiers that is used when formatting and parsing percentages.

NumberRounder NumberRounder NumberRounder NumberRounder NumberRounder

Gets or sets the current rounding strategy to be used when formatting percents.

NumeralSystem NumeralSystem NumeralSystem NumeralSystem NumeralSystem

Gets or sets the numbering system that is used to format and parse percentages.

ResolvedGeographicRegion ResolvedGeographicRegion ResolvedGeographicRegion ResolvedGeographicRegion ResolvedGeographicRegion

Gets the geographic region that was most recently used to format or parse percent values.

ResolvedLanguage ResolvedLanguage ResolvedLanguage ResolvedLanguage ResolvedLanguage

Gets the language that was most recently used to format or parse percent values.

SignificantDigits SignificantDigits SignificantDigits SignificantDigits SignificantDigits

Gets or sets the current padding to significant digits when a percent is formatted.

Methods

Format(Double) Format(Double) Format(Double) Format(Double) Format(Double)

Returns a string representation of a Double percentage.

Format(Int64) Format(Int64) Format(Int64) Format(Int64) Format(Int64)

Returns a string representation of an Int64 percentage.

Format(UInt64) Format(UInt64) Format(UInt64) Format(UInt64) Format(UInt64)

Returns a string representation of a UInt64 percentage.

FormatDouble(Double) FormatDouble(Double) FormatDouble(Double) FormatDouble(Double) FormatDouble(Double)

Returns a string representation of a Double percentage.

FormatInt(Int64) FormatInt(Int64) FormatInt(Int64) FormatInt(Int64) FormatInt(Int64)

Returns a string representation of an Int64 percentage.

FormatUInt(UInt64) FormatUInt(UInt64) FormatUInt(UInt64) FormatUInt(UInt64) FormatUInt(UInt64)

Returns a string representation of a UInt64 percentage.

ParseDouble(String) ParseDouble(String) ParseDouble(String) ParseDouble(String) ParseDouble(String)

Attempts to parse a string representation of a Double percentage.

ParseInt(String) ParseInt(String) ParseInt(String) ParseInt(String) ParseInt(String)

Attempts to parse a string representation of an integer percentage.

ParseUInt(String) ParseUInt(String) ParseUInt(String) ParseUInt(String) ParseUInt(String)

Attempts to parse a string representation of an unsigned integer percentage.

See Also