Forum Discussion

Marco's avatar
Marco
Contributor II
2 days ago

How to round the result of a calculation?

Hi everyone,

I would like to round the value for a calculation, I try wit this

api.Data.Calculate("A#P_EBPPrct:O#Import:U1#D0000:U2#P0000:U3#CORP_ADJ:U4#PJ00000 =  Round(Divide(A#433100, A#411000:E#" & strEntTx3 & ":C#Local:O#Top:U1#ALL_DEPARTMENTS:U2#PROMO:U3#CORP_RPT:U4#ALL_PROJECTS))")

or this

api.Data.Calculate("A#P_EBPPrct:O#Import:U1#D0000:U2#P0000:U3#CORP_ADJ:U4#PJ00000 =  Divide(A#433100, A#411000:E#" & strEntTx3 & ":C#Local:O#Top:U1#ALL_DEPARTMENTS:U2#PROMO:U3#CORP_RPT:U4#ALL_PROJECTS)",AddressOf OnEvalDataBuffer)

Private Sub OnEvalDataBuffer(ByVal api As FinanceRulesApi, ByVal evalName As String, ByVal eventArgs As EvalDataBufferEventArgs)
    Dim resultCells As New Dictionary(Of DataBufferCellPk, DataBufferCell)
    For Each sourceCell As DataBufferCell In eventArgs.DataBuffer1.DataBufferCells.Values
                sourceCell.CellAmount = math.round(sourceCell.CellAmount)
    Next

    eventArgs.DataBufferResult.DataBufferCells = eventArgs.DataBuffer1.DataBufferCells
End Sub

but didn't work, so, OS have a way to round values in a calculation?

2 Replies

  • jayaleck's avatar
    jayaleck
    New Contributor III

    try this -

    Private Sub OnEvalDataBuffer(ByVal api As FinanceRulesApi, ByVal evalName As String, ByVal eventArgs As EvalDataBufferEventArgs)

    Dim resultCells As New Dictionary(Of DataBufferCellPk, DataBufferCell)

    For Each kvp As KeyValuePair(Of DataBufferCellPk, DataBufferCell) In eventArgs.DataBufferResult.DataBufferCells

    Dim resultCell As DataBufferCell = kvp.Value

    If resultCell IsNot Nothing Then

    resultCell.CellAmount = Math.Round(resultCell.CellAmount, 2)

    End If

    Next

    End Sub

  • Your first example won't work because there is no Round function in OneStream.

    Your second example won't work because it is missing the Eval function