Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting a String to Float in Twig

Tags:

twig

Basically, I have set a parameter called "rating" that's equal to a product.DETAILS.STAR_RATING which is a value imported from a database-driven field which happens to be a string, I want to multiply this value by 20 but since "rating" is a string I cannot multiply it.

How do I convert the string to a float value?

{% set rating = product.DETAILS.STAR_RATING %} 
  {{rating * 20}}
like image 563
Mario Solorza Avatar asked Jun 29 '26 00:06

Mario Solorza


1 Answers

Very simple way, maybe strange but...

{% set rating = 0 + product.DETAILS.STAR_RATING %} 
{{ rating * 20}}
like image 140
BENARD Patrick Avatar answered Jul 03 '26 00:07

BENARD Patrick