I have a numeric value with four decimal places that I need to display with a leading zero when the value is less then 1 and if the value is greater then 1000, I need to add an appropriate comma (or period) separator.
How can I implement this?
Supposing that,
Size of Input | Example | Implementation |
---|---|---|
0 | Set output 0.0000 | Hardcode it |
0< mnInput <1 | Set Leading Zero 0.1230 | 1. Multiply input value by 10000 2. Convert it to String 3. lpad with 0 (to handle value .0123, 0012 or 0001) 4. Concatenation (or concat()) 0 and DECT(DecimalFormat - Decimal Format Character) and string value Example: mnNum_temp = [mnInputNumber]*10000 /* store temp value into mnNum_temp */ Convert Math_Numeric To String /* B8000094 - ConvertMath_NumericToString */ mnNum_Temp -> BF mnMathNumeric01 szString_temp <- BF szString szString_temp = lpad([szString_temp],"0",4) /* fill in zero till it for characters */ szOutputString = concat('0',concat('.',[szString_temp])) /* concat 3 components (0 + DECT + String value) */ |
>=1 | Set output 1,234,567.8900 (Comma Separator) | A. Decimal Notation 1234567B. Decimal Fraction 8900 1. Multiple 10000 then get the last 4 digit for Decimal FractionC. Concatenation Decimal Notation and DECT (DecimalFormat - Decimal Format Character) and Decimal Fraction |