cell.value is of type double, but display no decimal places

Posted by: hpmx on 8 September 2017, 2:23 pm EST

  • Posted 8 September 2017, 2:23 pm EST

    More precise:

    When filling the grid, the cells normally contain double values with two or more decimals places.

    I don`t want to show the decimal places in the cell to the user, but keep them nevertheless in the value field.

    Is this possible?

     

    regards hpm

     

  • Replied 8 September 2017, 2:23 pm EST

    hpm,


    The cell value always keeps the full precision regardless of the precision displayed.


    If you want the end user to only be able to enter numbers in the cell then you can use the NumberCellType with the DecimalPlaces property.  For example...


        NumberCellType cellType = new NumberCellType();
        cellType.DecimalPlaces = 0;
        fpSpread1.Sheets[0].Cells[0, 0].CellType = cellType;
        fpSpread1.Sheets[0].Cells[0, 0].Value = 12.34;


    If you want the end user to be able to enter both text and numbers in the cell then you can use te GeneralCellType with the NumberFormat property.  For example...


        System.Globalization.NumberFormatInfo formatInfo = new System.Globalization.NumberFormatInfo();
        formatInfo.NumberDecimalDigits = 0;
        GeneralCellType cellType = new GeneralCellType();
        cellType.NumberFormat = formatInfo;
        fpSpread1.Sheets[0].Cells[0, 0].CellType = cellType;
        fpSpread1.Sheets[0].Cells[0, 0].Value = 12.34;

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels