[Progress Communities] [Progress OpenEdge ABL] Forum Post: RE: Cannot transform JSON number value to ABL decimal value, JSON value has an exponent.

  • Thread starter Thread starter Peter Judge
  • Start date Start date
Status
Not open for further replies.
P

Peter Judge

Guest
Sadly that will only work on Windows. I've added a version of Valeriy's code into the OpenEdge.Core.Util.MathUtil class that will be in the next releases. The code is below FYI. /* Keep the default in a readonly property - it is 10 */ define static private property DEFAULT_BASE as integer initial 10 no-undo get. /** Converts an exponent (123e4) value into a decimal using a exponent base of 10. @param character The exponent value @param decimal The converted value */ method static public decimal ExponentialToDec(input pExpVal as character): return MathUtil:ExponentialToDec(pExpVal, DEFAULT_BASE). end method. /** Converts an exponent (123e4) value into a decimal. The format is nnn[.nnn]e[-]nnn e The is raised as a power of the exponent-base. @param character The exponent value @param integer The exponent base. Must be a positive value (>0) @param decimal The converted value */ method static public decimal ExponentialToDec(input pExpVal as character, input pBase as integer): define variable idx as integer no-undo. define variable decVal as decimal no-undo initial 0.00. define variable coefficient as decimal no-undo. define variable exponent as integer no-undo. if String:IsNullOrEmpty(pExpVal) then return decVal. Assert:IsPositive(pBase, 'Exponent base'). assign idx = index(pExpVal, 'e':u). if idx eq 0 then assign decVal = decimal(pExpVal). else assign coefficient = decimal(substring(pExpVal, 1, idx - 1)) exponent = integer(substring(pExpVal, idx + 1)) decVal = coefficient * exp(pBase, exponent) . return decVal. end method.

Continue reading...
 
Status
Not open for further replies.
Back
Top