EPPlus number format
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
In EPPlus, number formatting controls how Excel displays a value without changing the underlying numeric data. That distinction matters because a cell can still contain the same decimal, date serial number, or currency amount even though it appears differently to the user.
Most formatting work in EPPlus comes down to setting Style.Numberformat.Format with either a built-in Excel-style pattern or a custom format string. Once you understand that pattern language, formatting becomes predictable.
The Core EPPlus API
The main property you use is worksheet.Cells[row, column].Style.Numberformat.Format.
The cell still contains the numeric value 1234.567, but Excel displays it as 1234.57 because the format rounds the display to two decimal places.
Common Format Strings
Excel format strings are reused by EPPlus, so the same patterns you know from Excel generally apply here.
Examples:
- '
0for integer-style display' - '
0.00for two decimal places' - '
#,##0for thousands separators' - '
#,##0.00for grouped decimals' - '
0%or0.00%for percentages' - '
yyyy-mm-ddfor date display' - '
$#,##0.00for currency-style output'
Example with several formats:
Dates Are Numbers Too
Excel stores dates internally as serial numbers. EPPlus follows that model, so a date format only affects presentation.
Without a date format, Excel may show the raw serial number instead of a human-readable date.
That is one of the most common surprises for new EPPlus users.
Custom Formatting Is Often Better Than Converting to Strings
A tempting mistake is to pre-format values as strings in C# before writing them to Excel. That makes the spreadsheet look right, but it destroys the numeric type and prevents Excel from sorting, filtering, and calculating properly.
Prefer this:
Not this:
The first cell is numeric with display formatting. The second is just text.
Reuse Styles for Large Sheets
If you format many cells individually, performance can degrade. A better pattern is to apply formatting to ranges or columns.
This is cleaner and more efficient than formatting thousands of cells one by one.
Handling Locale Expectations
Excel format strings use Excel’s formatting rules, not your current C# culture settings. That means a format like #,##0.00 describes the style, while Excel will render separators based on the user’s environment.
If your export has strict locale expectations, test the resulting workbook in the target Excel environment instead of assuming the display will look identical everywhere.
Common Pitfalls
A common mistake is writing already-formatted strings instead of numeric values. That makes later calculations and sorting harder or impossible.
Another mistake is forgetting to format dates, which leads Excel to display serial numbers rather than calendar values.
Developers also mix C# formatting assumptions with Excel formatting syntax. EPPlus uses Excel-style format patterns, not decimal.ToString(...) format strings.
Finally, be careful with large sheets. Applying per-cell styling unnecessarily can slow generation significantly.
Summary
- EPPlus number formatting controls display, not the underlying cell value.
- Use
Style.Numberformat.Formatwith Excel-style format strings. - Keep numbers as numbers and dates as dates instead of converting them to strings.
- Apply styles to ranges or columns when possible for better performance.
- Test date, currency, and locale-sensitive exports in real Excel when formatting accuracy matters.
Related reading
- Equivalent of Ihostedservice in asp.net framework for background tasks
- Equivalent to 'app.config' for a library DLL
- Equivalent to C's using keyword in powershell?
- Error - The transaction associated with the current connection has completed but has not been disposed
- Error CS1705 which has a higher version than referenced assembly
- Error Invalid option ''6'' for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default
- error Unable to find vcvarsall.bat
- Escape command line arguments in c

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.