F_CONVERT_DECIMAL_TO_STRING

//Function Name : f_convert_decimal_to_string
//Argument Name : adec_value, Arg Type : decimal, Pass By : Value
//Return Type : String
//Example : adec_value = 5.5000
//Return : "5.5"

long ll_value_temp, ll_value_decimal, ll_pos
string ls_value

If adec_value = 0 Then Return "0"

ll_value_temp = Truncate(adec_value, 0)

ll_value_decimal = (adec_value - ll_value_temp) * 10000

ll_pos = 5

If Mid(string(ll_value_decimal), 4, 1) = "0" Then
    ll_pos = 4
    If Mid(string(ll_value_decimal), 3, 1) = "0" Then
        ll_pos = 3
        If Mid(string(ll_value_decimal), 2, 1) = "0" Then
            ll_pos = 2
            If Mid(string(ll_value_decimal), 1, 1) = "0" Then
                ll_pos = 1
            End If
        End If
    End If
End If

If ll_value_decimal = 0 Then ll_pos = 1

If ll_pos - 1 = 0 Then
    ls_value = string(ll_value_temp)
Else
    ls_value = string(ll_value_temp) + "." + left(string(ll_value_decimal), ll_pos - 1)
End If

Return ls_value

0 comments:

Post a Comment