set formulae to truncate decimal to 2 decimal

Posted by: lier on 8 September 2017, 2:08 pm EST

  • Posted 8 September 2017, 2:08 pm EST

    <P>hii,</P>
    <P>i need to set formulae to truncate decimal to 2 decimal in farpoint spread. </P>
    <P>i used the following code:</P>
    <P> fpspread.sheet[0].setformulae(0,0,"trunc(Convert.todecimal(fpspread.sheet[0].cells[0,0].text),2)</P>
    <P> but it is raising exception.</P>
    <P>ami going wrong somewhere?</P>
    <P>kindly help</P>
  • Replied 8 September 2017, 2:08 pm EST

    <p>Lier,</p><p>An alternative approach would be to set the cell or the column in which the formula is being applied to a NumberCellType and set the decimal places for the entire column or cell as desired.And then apply the formula as required.Something as follows:<br></p><p>       Dim numcell As New FarPoint.Win.Spread.CellType.NumberCellType<br>        numcell.DecimalPlaces = 2<br>        FpSpread1.ActiveSheet.Cells(9, 3).CellType = numcell<br>        FpSpread1.ActiveSheet.Cells(9, 3).Formula = "Your formula"<br></p><p>Thanks <br></p>
  • Replied 8 September 2017, 2:08 pm EST

    <P>lier,</P>
    <P>From your code, I am not sure what you are attempting to do.</P>
    <P>If you already have a value in the cell and you what it displayed to 2 decimal places then you could use a cell type as SureshD suggested.</P>
    <P>If you want to use a formula to compute a value to 2 decimal places then you could use code like...</P>
    <P>    fpSpread1.Sheets[0].Cells[0, 0].Value = 1234.5678;<BR>    fpSpread1.Sheets[0].Cells[0, 1].Formula = "TRUNC(A1,2)";</P>
    <P>or...</P>
    <P>    fpSpread1.Sheets[0].SetValue(0, 0, 1234.5678);<BR>    fpSpread1.Sheets[0].SetFormula(0, 1, "TRUNC(A1,2)");</P>
    <P>Spread's formulas support several rounding functions including ROUND, ROUNDDOWN, ROUNDUP, MROUND, TRUNC, CEILING, FLOOR.<BR></P>
Need extra support?

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

Learn More

Forum Channels