This section focuses on formatting the weight range (e.g., “10 – 20 lbs”) into a more readable format with one decimal place.
- Assign Original String: The weight range string is stored in the
dimension_rangevariable.
<#assign dimension_range = itemLineDetails.weightrange />
- Extract Numeric and Unit Parts: The numeric part of the weight range is separated from the unit (
lbs), allowing for easier processing.
<#assign numeric_part = dimension_range?replace(" lbs", "") />
<#assign unit = "lbs" />
- Split Numeric Part: The numeric part is split into individual values using the
' - 'delimiter.
<#assign range_parts = numeric_part?split(" - ") />
- Initialize Formatted String: A variable
formatted_rangeis initialized to store the formatted result.
<#assign formatted_range = "" />
- Loop Through Parts: The code loops through each range part, converting it to a number and formatting it to one decimal place.
<#list range_parts as part>
<#assign formatted_part = (part?number)?string("0.0") />
- Concatenate Formatted Parts: The formatted parts are concatenated with the appropriate delimiter (
" - "), and finally, the unit (lbs) is added.
<#if part_has_next>
<#assign formatted_range += formatted_part + " - " />
<#else>
<#assign formatted_range += formatted_part />
</#if>
</#list>
<#assign formatted_range += " " + unit />
- Output the Result: The formatted weight range is then output.
${formatted_range}