Specifying Significant Digits to be Stored in Excel File with Node.js via C++

Possible Usage Scenarios

By default, Aspose.Cells for Node.js via C++ stores 17 significant digits of double values inside the Excel file, unlike MS-Excel which stores only 15 significant digits. You can change the default behavior of Aspose.Cells from 17 significant digits to 15 significant digits using the CellsHelper.getSignificantDigits() property.

Specifying Significant Digits to be stored in Excel file

The following sample code enforces Aspose.Cells to use 15 significant digits while storing double values inside the Excel file. Please check the output excel file. Change its extension to .zip and unzip it and you will see, only 15 significant digits are stored inside the Excel file. The following screenshot explains the effect of CellsHelper.getSignificantDigits() property on the output Excel file.

todo:image_alt_text

Sample Code

const path = require("path");
const AsposeCells = require("aspose.cells.node");

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");

// By default, Aspose.Cells stores 17 significant digits unlike
// MS-Excel which stores only 15 significant digits
AsposeCells.CellsHelper.setSignificantDigits(15);

// Create workbook
const workbook = new AsposeCells.Workbook();

// Access first worksheet
const worksheet = workbook.getWorksheets().get(0);

// Access cell A1
const c = worksheet.getCells().get("A1");

// Put double value, only 15 significant digits as specified by
// CellsHelper.SignificantDigits above will be stored in excel file just like MS-Excel does
c.putValue(1234567890.123451711);

// Save the workbook
workbook.save(path.join(dataDir, "out_SignificantDigits.xlsx"));