I am working in Opencart 2.3 & I have run into a situation where we need decimals converted into fractions. I am working with the category.tpl page, and we have our products outputted into a list on the page. The Attributes vary per product.
Example; One page has the Attributes Color, Length A, and Length B. Product A's data is currently outputting in the chart as: Blue, 5.5, 10.75. We would like it to output: Blue, 5 1/2, 10 3/4
Is there anyway to put the variable $attribute['text']; into a filter, that spits out a fraction (instead of the decimal)? Also, note that we would need Blue to spit out Blue still.
-Thanks, Michael P.
Here is the code below:
<?php if ($product['attribute_groups']) { ?>
<?php foreach ($product['attribute_groups'] as $attribute_group) { ?>
<?php foreach ($attribute_group['attribute'] as $attribute) { ?>
<div class="attGroup matchHeight"><?php echo $attribute['text']; ?> </div>
<?php } ?>
<?php } ?>
<?php } ?>
with help of this algorithm: Converting float decimal to fraction
try this:
Assuming there is only a few fractions being realisticly used, you might prevously register them, then use this registry to convert any decimal value found.
It might be something like this:
Then your HTML part would be: