Start a new topic

Rounding in API

Hi,

I have a custom function in API to round GPA to 2 decimal positions.  Our data comes in as one of the following:

4

3.987

3.8

My format works perfectly for 4 and 3.987 (returns 4.00 and 3.99) but it will not add a zero to 3.8 and return 3.80.  This is my code:

    _
    Public Function ComputedColumn_635820736041191577( _
                ByVal oField as ImportOM.API.iField, _
                ByVal Cancel As ImportOM.API.iCancel) As String
        'This function must return a text value
        Dim sReturn As String
         Dim sGPA As String
       
            sReturn = import.fields.GetByExcelName ("AN").Value
            sGPA = Format (sReturn,"Fixed")
           
        Return sGPA
    End Function

I've also tried Format (sReturn, "0.00) to no avail.  The weird thing is when I test the data in my profile it returns 3.80 but this does not import to RE correctly.

Any ideas?

Thanks.

Lisa


Try this for formatting

sReturn = Strings.FormatNumber(sReturn, 2, TriState.False, TriState.False, TriState.False)

Reference here:
https://msdn.microsoft.com/en-us/library/microsoft.visualbasic.strings.formatnumber(v=vs.110).aspx
Thanks for the code Wayne but that didn't work either. Maybe RE is rounding it back to 1 decimal because when I run it through the code test in importOmatic it works but does not in a real import. Thanks again for your help.
Login or Signup to post a comment