Forum Discussion

uvrao33's avatar
uvrao33
New Contributor II
8 hours ago

How to get two decimal places in Member formula

Hi Everyone,

I'm trying to write member formula (not dynamic calc), below is the syntax

Dim Var1 as Decimal = Math.Round(api.Data.GetDataCell("A#630000").CellAmount, 2)

api.Data.Calculate("A#520000 = A#430000 "*" & Var1 & "). after that getting error "Double is not valid, input string was incorrect format".

2 Replies

  • rhankey's avatar
    rhankey
    Contributor III

    In short, the error you are getting is because you are attempting to concatenate a Decimal datatype without any conversion into a String.  The simple fix would be:

    api.Data.Calculate("A#520000 = A#430000 *" & Var1.ToString & ")

    However, the above is problematic depending on the culture of the user running the script, should let's say they format numbers as "0.000,00" rather than "0,000.00".  The safer way to do what you are doing is as follows:

    Dim Var1 as Decimal = Math.Round(api.Data.GetDataCell("A#630000").CellAmount, 2)

    api.Data.FormulaVariables.SetDecimalVariable("Var1",Var1)

    api.Data.Calculate("A#520000 = A#430000 * $Var1")