Hubspot calculated property

New Contributor

Hi,

 

I have created an personalised email in which we need to perform some calculation. The veriables are holding the data in string and trying to convert it into integer but for some reason the variable is giving me value 0 after conversion.

 

I am using "|int" filter for data conversion. Do ineed to use some other method not sure would need help with the same.

Reply
0 Upvotes
2 Replies 2
HubSpot Moderator

Hi @sachinFlock,

 

I've been playing around with this. When I run this code:

 

{% set numericString = "1" %}
<p>numericString: {{ numericString }}</p>
<p>type(numericString): {{ type(numericString) }}</p>

{% set numericStringToNum = numericString|int %}
<p>numericStringToNum: {{ numericStringToNum }}</p>
<p>type(numericStringToNum): {{ type(numericStringToNum) }}</p>

 

My second variable does come back as an integer type, with a value of 1. For what it's worth, I'm running my code in an email custom module. Could you tell me more about where specifically you're running your code? Or feel free to link me to your module so I can take a look.

 

Thanks.

Leland Scanlan

HubSpot Developer Support
Reply
0 Upvotes
Highlighted
New Contributor

Hi @lscanlan,

Thanks for replying.

I'm working with a personalization token in the Email Manager. The converted type is integer but it returns 0.

Here's my code...

{% set percent_gb = personalization_token('contact.custom_file_storage_in_percentage', '0') %} 
{% set percent_gb_int = percent_gb|int %}
<p>{{ type(percent_gb) }}: {{ percent_gb }}</p> <!-- str: 47 -->
<p>{{ type(percent_gb_int) }}: {{ percent_gb_int }}</p> <!-- int: 0 -->

 

Thanks,
Sachin Vishwakarma
Flock.

Reply
0 Upvotes