How to display very long numbers in a cell without rounding off in C#, VB.NET?
This article explains how to display very long numbers without rounding off in XlsIO.
Microsoft Excel displays all digits of a numeric value in the cell if its digit count does not exceed the maximum count, with respect to system resolution. Otherwise, it is displayed in exponential format. This is the same in XlsIO, and it is not possible to retrieve the entire cell value as entered, through DisplayText. Therefore, the cell’s number format should be set to text to retrieve the number as entered.
To know more about applying number formats, please refer to the documentation.
The following C#/VB complete code snippet explains how to display very long numbers without rounding off using XlsIO.
C#
using Syncfusion.XlsIO; using System.IO; namespace LongNumber_WithoutRounding { class Program { static void Main(string[] args) { using (ExcelEngine excelEngine = new ExcelEngine()) { IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Excel2013; // Create a new workbook IWorkbook workbook = application.Workbooks.Create(1); // Access the first worksheet in the workbook IWorksheet worksheet = workbook.Worksheets[0]; // Entering a long number with text number format worksheet.Range["A1"].NumberFormat = "@"; worksheet.Range["A1"].Value = "1234567890987654321"; // Autofit column to view view entire cell contents worksheet.AutofitColumn(1); // Saving the workbook as stream Stream outputStream = File.Create("Output.xlsx"); workbook.SaveAs(outputStream); } } } }
VB
Imports System.IO Imports Syncfusion.XlsIO Namespace LongNumber_WithoutRounding Class Program Private Shared Sub Main(ByVal args() As String) Using excelEngine As ExcelEngine = New ExcelEngine Dim application As IApplication = excelEngine.Excel application.DefaultVersion = ExcelVersion.Excel2013 'Create a new workbook Dim workbook As IWorkbook = application.Workbooks.Create(1) 'Access the first worksheet in the workbook Dim worksheet As IWorksheet = workbook.Worksheets(0) 'Entering a long number with text number format worksheet.Range("A1").NumberFormat = "@" worksheet.Range("A1").Value = "1234567890987654321" 'Autofit column to view view entire cell contents worksheet.AutofitColumn(1) 'Saving the workbook as stream Dim outputStream As Stream = File.Create("Output.xlsx") workbook.SaveAs(outputStream) End Using End Sub End Class End Namespace
Take a moment to peruse the documentation where you can find basic Excel document processing options along with the features like import and export data, chart, formulas, conditional formatting, data validation, tables, pivot tables and, protect the Excel documents, and most importantly, the PDF, CSV and Image conversions with code examples.
Conclusion
I hope you enjoyed learning about How to display very long numbers in a cell without rounding off in C#, VB.NET.
You can refer to our XIsIO’s feature tour page to learn about its other groundbreaking features. Explore our UG documentation and online demos to understand how to manipulate data in Excel documents.
If you are an existing user, you can access our latest components from the License and Downloads page. For new users, you can try our 30-day free trial to check out XlsIO and other Syncfusion® components.
If you have any queries or require clarification, please let us know in the comments below or contact us through our support forums, Support Tickets, or feedback portal. We are always happy to assist you!