Share via


Sys.CultureInfo.numberFormat Property

Gets an object that contains an array of culture-sensitive formatting and parsing strings values that can be applied to Number type extensions.

var cultureObject = Sys.CultureInfo.CurrentCulture;
var nfObject = cultureObject.numberFormat;

Return Value

An object that contains an array of culture-sensitive formatting strings.

Remarks

Use the numberFormat field to retrieve an object that contains an array of formatting strings that are based on the current culture or on the invariant culture. Each formatting string can be used to specify how to format Number type extensions.

Example

The following example shows how to use the numberFormat field of the Sys.CultureInfo class based on the current culture. The culture attribute of the <configuration> section in the Web.config file must also be set to "auto". For more information about culture settings, see Walkthrough: Globalizing a Date by Using Client Script.

<script type="text/javascript">
    // Create the CurrentCulture object
    var cultureObject = Sys.CultureInfo.CurrentCulture;
    // Get the name field of the CurrentCulture object
    var cultureName = cultureObject.name;
    // Get the numberFormat object from the CurrentCulture object
    var nfObject = cultureObject.numberFormat;
    // Create an array of format types
    var myArray = ['CurrencyDecimalDigits', 'CurrencyDecimalSeparator', 'IsReadOnly', 'CurrencyGroupSizes',
                   'NumberGroupSizes', 'PercentGroupSizes', 'CurrencyGroupSeparator',  
                   'CurrencySymbol', 'NaNSymbol', 'CurrencyNegativePattern', 'NumberNegativePattern',  
                   'PercentPositivePattern', 'PercentNegativePattern', 'NegativeInfinitySymbol',  
                   'NegativeSign', 'NumberDecimalDigits', 'NumberDecimalSeparator',  
                   'NumberGroupSeparator', 'CurrencyPositivePattern', 'PositiveInfinitySymbol',  
                   'PositiveSign', 'PercentDecimalDigits', 'PercentDecimalSeparator',  
                   'PercentGroupSeparator', 'PercentSymbol', 'PerMilleSymbol',  
                   'NativeDigits', 'DigitSubstitution'];

    var result = 'Culture Name: ' + cultureName;
    for (var i = 0, l = myArray.length; i < l; i++) {
        var arrayVal = myArray[i];
        if (typeof(arrayVal) !== 'undefined') {
            result += "<tr><td>" + arrayVal + "</td><td>" + eval("nfObject." + arrayVal) + '</td></tr>';
        }
    }
    var resultHeader = "<tr><td><b>FormatType</b></td><td><b>FormatValue</b></td></tr>"
    $get('Label1').innerHTML = "<table border=1>" + resultHeader + result + "</table>";

    var n = 99.987;
    $get('Label2').innerHTML = "<p/><h3>numberFormat Example: </h3>" + 
    n.localeFormat("C");

 </script>
<script type="text/javascript">
    // Create the CurrentCulture object 
    var cultureObject = Sys.CultureInfo.CurrentCulture;
    // Get the name field of the CurrentCulture object 
    var cultureName = cultureObject.name;
    // Get the numberFormat object from the CurrentCulture object 
    var nfObject = cultureObject.numberFormat;
    // Create an array of format types 
    var myArray = ['CurrencyDecimalDigits', 'CurrencyDecimalSeparator', 'IsReadOnly', 'CurrencyGroupSizes',
                   'NumberGroupSizes', 'PercentGroupSizes', 'CurrencyGroupSeparator', 
                   'CurrencySymbol', 'NaNSymbol', 'CurrencyNegativePattern', 'NumberNegativePattern', 
                   'PercentPositivePattern', 'PercentNegativePattern', 'NegativeInfinitySymbol', 
                   'NegativeSign', 'NumberDecimalDigits', 'NumberDecimalSeparator', 
                   'NumberGroupSeparator', 'CurrencyPositivePattern', 'PositiveInfinitySymbol', 
                   'PositiveSign', 'PercentDecimalDigits', 'PercentDecimalSeparator', 
                   'PercentGroupSeparator', 'PercentSymbol', 'PerMilleSymbol', 
                   'NativeDigits', 'DigitSubstitution'];

    var result = 'Culture Name: ' + cultureName;
    for (var i = 0, l = myArray.length; i < l; i++) {
        var arrayVal = myArray[i];
        if (typeof(arrayVal) !== 'undefined') {
            result += "<tr><td>" + arrayVal + "</td><td>" + eval("nfObject." + arrayVal) + '</td></tr>';
        }
    }
    var resultHeader = "<tr><td><b>FormatType</b></td><td><b>FormatValue</b></td></tr>"
    $get('Label1').innerHTML = "<table border=1>" + resultHeader + result + "</table>";

    var n = 99.987;
    $get('Label2').innerHTML = "<p/><h3>numberFormat Example: </h3>" + 
    n.localeFormat("C");

 </script>

See Also

Reference

Sys.CultureInfo Class

Other Resources

Language Reference