Change the format of product rating value (number)

Hi is it possible to round or change the format of product rating value in bricks? I think we should use rtrim() function but i don’t know how :sweat_smile:

Right now i use {woo_product_rating:value} and the outputs are numbers like:
1.00
2.50
3.70
4.00

I need to show the values like:
1
2.5
3.7
4

Asked ChatGpt and it made that function:

function formatProductRating($rating) {
    // Check if the rating is a whole number (integer)
    if (floor($rating) == $rating) {
        // If it's a whole number, just return it as is
        return (int)$rating;
    } else {
        // If it's not a whole number, format it with one decimal place
        return number_format($rating, 1);
    }
}


You can then call:

{echo:formatProductRating({woo_product_rating:value})}
1 Like

thank you, does it work for you?
it works fine for non integer numbers (3.5)
but for integer number it shows me the default numbers like 4.00

I updated the code above, so it takes into account that case (it does a typecast to int for the whole number).