# Culture Specific Predefined Formats

Starting with R3 2021, `SpreadStreamProcessing` exposes the `BuiltInNumberFormats` static class. This class contains several methods that allow you to get a set of predefined formats. These formats are culture-specific and depend on the current culture of the operating system. For example, if you set a currency format, you get the currency symbol for the current culture. The following methods are available:

| Method                    | Format in en-US culture                             | Description                                                                                                                                                       |
| ------------------------- | --------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `GetGeneral`              | General                                             | Generates the General number format string.                                                                                                                       |
| `GetNumber`               | 0                                                   | Generates a Number number format string.                                                                                                                          |
| `GetNumber1`              | 0.00                                                | Generates a Number number format string with 2 decimal places and no thousand separator.                                                                          |
| `GetNumber2`              | #,##0                                               | Generates a Number number format string with zero decimal places and a thousand separator.                                                                        |
| `GetNumber3`              | #,##0.00                                            | Generates a Number number format string with 2 decimal places and a thousand separator.                                                                           |
| `GetCurrency`             | $#,##0\_);($#,##0)                                  | Generates a Currency number format string with no decimal places, and positive and negative format patterns and alignment.                                        |
| `GetCurrency1`            | $#,##0\_);\[Red]\($#,##0)                           | Generates a Currency number format string with no decimal places, and positive and negative format with red digits patterns and alignment.                        |
| `GetCurrency2`            | $#,##0.00\_);($#,##0.00)                            | Generates a Currency number format string with two decimal places, and positive and negative format patterns and alignment.                                       |
| `GetCurrency3`            | $#,##0.00\_);\[Red]\($#,##0.00)                     | Generates a Currency number format string with two decimal places, and positive and negative format with red digits patterns and alignment.                       |
| `GetPercent`              | 0%                                                  | Generates a Percent number format string.                                                                                                                         |
| `GetPercent1`             | 0.00%                                               | Generates a Percent number format string with 2 decimal places and no thousand separator.                                                                         |
| `GetScientific`           | 0.00E+00                                            | Generates a culture-dependent Scientific number format string.                                                                                                    |
| `GetFraction`             | # ?/?                                               | Generates a Fraction number format for up to one digit.                                                                                                           |
| `GetFraction1`            | # ??/??                                             | Generates a Fraction number format for up to two digits.                                                                                                          |
| `GetShortDate`            | m/d/yyyy                                            | Generates a Date number format for short date.                                                                                                                    |
| `GetDayMonthYear`         | d-mmm-yy                                            | Generates a Date number format with day, month, and year.                                                                                                         |
| `GetDayMonth`             | d-mmm                                               | Generates a Date number format with day and month.                                                                                                                |
| `GetMonthYear`            | mmm-yy                                              | Generates a Date number format with month and year.                                                                                                               |
| `GetHourMinuteAMPM`       | h:mm AM/PM                                          | Generates a Time number format with hours, minutes, and AM/PM.                                                                                                    |
| `GetHourMinuteSecondAMPM` | h:mm:ss AM/PM                                       | Generates a Time number format with hours, minutes, seconds, and AM/PM.                                                                                           |
| `GetHourMinute`           | h:mm                                                | Generates a Time number format with hours and minutes.                                                                                                            |
| `GetHourMinuteSecond`     | h:mm:ss                                             | Generates a Time number format with hours, minutes, and seconds.                                                                                                  |
| `GetShortDateHourMinute`  | m/d/yyyy h:mm                                       | Generates a Time number format with short date, hours, and minutes.                                                                                               |
| `GetDayMonthLongYear`     | m/d/yyyy                                            | Generates a Date number format with day, month, and year.                                                                                                         |
| `GetNumber4`              | #,##0\_);(#,##0)                                    | Generates a Currency number format string with no decimal places, a thousand separator, and positive and negative format pattern and alignment.                   |
| `GetNumber5`              | #,##0\_);\[Red]\(#,##0)                             | Generates a Currency number format string with no decimal places, a thousand separator, and positive and negative format with red digits patterns and alignment.  |
| `GetNumber6`              | #,##0.00\_);(#,##0.00)                              | Generates a Currency number format string with two decimal places, a thousand separator, and positive and negative format pattern and alignment.                  |
| `GetNumber7`              | #,##0.00\_);\[Red]\(#,##0.00)                       | Generates a Currency number format string with two decimal places, a thousand separator, and positive and negative format with red digits patterns and alignment. |
| `GetCurrency4`            | *(\*#,##0*);*(\*(#,##0);*(\* "-"*);*(@\_)           | Generates a Currency number format string with no decimal places and no currency symbol.                                                                          |
| `GetCurrency5`            | *($\*#,##0*);*($\*(#,##0);*($\* "-"*);*(@\_)        | Generates a Currency number format string with no decimal places and a currency symbol.                                                                           |
| `GetCurrency6`            | *(\*#,##0.00*);*(\*(#,##0.00);*(\*"-"??*);*(@\_)    | Generates a Currency number format string with two decimal places and no currency symbol.                                                                         |
| `GetCurrency7`            | *($\*#,##0.00*);*($\*(#,##0.00);*($\*"-"??*);*(@\_) | Generates a Currency number format string with two decimal places and a currency symbol.                                                                          |
| `GetScientific2`          | ##0.0E+0                                            | Generates a Scientific number format string with the displayed exponent pattern.                                                                                  |

## Working with the BuiltInNumberFormats Class

The following example demonstrates how you can get a specific format and set it when exporting a cell.

**Example 1: Apply a culture-specific fraction format to an exported cell value**

```C#
SpreadCellFormat format = new SpreadCellFormat();
format.NumberFormat = BuiltInNumberFormats.GetFraction();

using (ICellExporter cell = row.CreateCellExporter())
{
    cell.SetValue(0.5);
    cell.SetFormat(format);
}
```

## Invariant Number Formats

By default, the `NumberFormat` property of `SpreadCellFormat` and `SpreadCellStyle` accepts a format code that is interpreted according to the current culture. To set the format code exactly as it appears in the Open XML model, regardless of the current culture, use the `InvariantNumberFormat` property.

The following rules apply to `InvariantNumberFormat`:

* The value is an invariant Excel format code (for example, `#,##0.00` or `yyyy-mm-dd`), not a .NET format string.
* The following canonical numeric codes are exported as built-in formats with their fixed IDs: `0`, `0.00`, `#,##0`, `#,##0.00`, `0%`, `0.00%`, `0.00E+00`, `# ?/?`, `# ??/??`, `#,##0_);(#,##0)`, `#,##0_);[Red](#,##0)`, `#,##0.00_);(#,##0.00)`, `#,##0.00_);[Red](#,##0.00)`, and `##0.0E+0`.
* Any other code is preserved unchanged as a custom format.
* An empty string applies the General format, and `null` clears the override.
* `NumberFormat` and `InvariantNumberFormat` are mutually exclusive. The last assignment to either property determines which one is used, even when the string is unchanged. The inactive property returns `null`.

**Example 2: Apply an invariant number format to an exported cell**

```csharp
using (ICellExporter cell = row.CreateCellExporter())
{
    SpreadCellFormat format = new SpreadCellFormat
    {
        InvariantNumberFormat = "#,##0.00"
    };

    cell.SetFormat(format);
    cell.SetValue(1234.5);
}
```

## See Also

* [Cells](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadstreamprocessing/model/cells)
* [Workbook](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadstreamprocessing/model/workbook)
