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.
It does not consider decimal point
The number of zeros followed by a specific value is not consistent (6 or 7 depends on input value)
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:
Input parameter: F41002.CONV (or equivalent variable numeric value with 7 display decimal)
Output parameter: String value (for this example, szStringOutput)
Variables:
rpt_mnConvPW10: To hold value without display decimal
rpt_mnDecimalFraction_CONV: (math_numeric, to hold fraction part of value)
rpt_mnNonFraction_MATH01: (math_numeric, to hold non fraction part of value)
rpt_szNonFractionString_DL01: (string, to describe non fraction part of value)
rpt_szDecimalFractionStr_DL01: (string, to describe fraction part of value)
rpt_mnSizeOfNonFraction_MATH01: (math_numeric, to hold the size of non fraction part)
Action plan
Test whether input value has decimal fraction or not (e.g., 1.2345000)
Test whether non fractional part is 0 or not (e.g., 1)
Split input value into Decimal Fraction and non decimal fraction (e.g., 1 and 2345000)
Manipulate string value (e.g., 2345000 to 2345)
Concatenate (e.g., 1.2345)
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:
This is only one example of a possible implementation so there can be other ways to implement this same logic.
The Expression Manager function mod(number,number) returns the remainder of X/Y. This is useful to check whether a certain input value contains a decimal fraction or not.
To have valid value direct assignment (auto-conversion from math_numeric to string) is used in multiple places
This is provided simply as an example. Oracle is not responsible for any customized code implemented by customers. This document may contain information, software, products or services which are not supported by Oracle Support Services and are being provided "as is" without warranty. Please refer to the following site for My Oracle Support Terms of Use: https://support.oracle.com/CSP/ui/TermsOfUse.html