How to Convert a Numeric Value to a String without Trailing Zeros for Irregular Display Decimals

Purpose of Document

To give proper conversion information to warehouse staff we need to convert the Item Unit of Measure Conversion Factor, F41002.CONV, to a String Value without having trailing zeros.

We have tried using business function B8000094 - ConvertMath_NumericToString (Convert Math_Numeric To String) which does not give us the desired result.

For example,

F41002.CONV (15 [7]) Result of using ConvertMath_NumericToString (B8000094) Desired Result
20.0000000 200000000 20
.0400000 0400000 0.04
1.2345000 12345000 1.2345
4800.0000000 4800000000 4800

How can I convert this value to a string value and omit the unwanted trailing zeros?

The business function B8000094 - ConvertMath_NumericToString (Convert Math_Numeric To String) is meant for conversion of an amount with two display decimals. When using this business function on values with a different number of display decimals other than two, the conversion result through this business function may yield incorrect results.

One possible implementation to achieve the desired results is below:

The following is an example of a possible routine to get the desired string output (comment and statement is written inside routine).

// ======================================================================
//1. Check Decimal Fraction based on F41002.CONV
// ======================================================================
VA rpt_mnDecimalFraction_CONV = mod([BC Conversion Factor (F41002)(CONV)],1)

//
// ======================================================================
// 2. Direct conversion from Math_Numeric to String for Non Fraction Part
// This value will be tested later on
// ======================================================================
VA rpt_mnNonFraction_MATH01 = [BC Conversion Factor (F41002)(CONV)]-[VA rpt_mnDecimalFraction_CONV]

//
// ======================================================================
// 3. Fraction Part (Direct Conversion)
// ======================================================================
VA rpt_szNonFractionString_DL01 = mod([BC Conversion Factor (F41002)(CONV)],1)

//
// ======================================================================
// 4. To get Non-Fraction Part (multiply pow10(7) and substring
// ======================================================================
VA rpt_mnConvPW10 = [BC Conversion Factor (F41002)(CONV)]*pow10(7)

VA rpt_mnSizeOfNonFraction_MATH01 = length([VA rpt_mnConvPW10])
VA rpt_mnSizeOfNonFraction_MATH01 = [VA rpt_mnSizeOfNonFraction_MATH01]-7
If VA rpt_mnSizeOfNonFraction_MATH01 is greater than <Zero>
// it has value (e.g., 20, 1 and 4800)
VA rpt_szNonFractionString_DL01 = substr([VA rpt_mnConvPW10],0,[VA rpt_mnSizeOfNonFraction_MATH01])
Else
VA rpt_szNonFractionString_DL01 = "0"
End If
//
// ======================================================================
// 5. To handle Decimal Fraction part
// ======================================================================
If VA rpt_mnDecimalFraction_CONV is greater than <Zero>

// if mnDecimalFration > 0 then it contains decimal value
VA rpt_szDecimalFractionStr_DL01 = rtrim([VA rpt_mnDecimalFraction_CONV],"0")
If VA rpt_mnNonFraction_MATH01 is greater than <Zero>
// *** Example: 1.2345000 ***
RV szStringOutput = concat([VA rpt_szNonFractionString_DL01],[VA rpt_szDecimalFractionStr_DL01])
Else
// *** Example: 0.0400000 ***
RV szStringOutput = concat('0',[VA rpt_szDecimalFractionStr_DL01])
End If
Else
// *** Example: 4800.0000000 ***
VA rpt_szDecimalFractionStr_DL01 = ""
RV szStringOutput = VA rpt_szNonFractionString_DL01
End If

Note: