# calculate from facts

**URL:** <https://forum.ansible.com/t/calculate-from-facts/14570>\
**Category:** Ansible Project\
**Created:** [February 14, 2014, 10:59pm UTC](https://forum.ansible.com/t/calculate-from-facts/14570 "2014-02-14T22:59:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Patrik\_Uytterhoeven](https://avatars.discourse-cdn.com/v4/letter/p/0ea827/32.png) [@Patrik\_Uytterhoeven](https://forum.ansible.com/u/Patrik_Uytterhoeven)\
**Post date:** [February 14, 2014, 10:59pm UTC](https://forum.ansible.com/t/calculate-from-facts/14570/1 "2014-02-14T22:59:30Z")

</div>

hi,

i would like to calculate 75% from from my memory  
if i read my pc memory from facts i can calculate it by multiplying it by 0.75  
but that number will not always be a round number sometimes it will be a float

is there anyway to calculate the facts and drop what is behind the period ?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [February 17, 2014, 3:15pm UTC](https://forum.ansible.com/t/calculate-from-facts/14570/2 "2014-02-17T15:15:07Z")

</div>

something like {{ansible\_memory \* 0.75|int }} ?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [February 17, 2014, 3:35pm UTC](https://forum.ansible.com/t/calculate-from-facts/14570/3 "2014-02-17T15:35:30Z")

</div>

Also, take a look at the “set\_fact” module…

---

<div class="post-metadata">

**Author:** ![Nico\_K](https://avatars.discourse-cdn.com/v4/letter/n/46a35a/32.png) [@Nico\_K](https://forum.ansible.com/u/Nico_K)\
**Post date:** [July 24, 2014, 9:14am UTC](https://forum.ansible.com/t/calculate-from-facts/14570/4 "2014-07-24T09:14:34Z")

</div>

I’m actually using this in a template, however the behavior is not as expected:

someVar = {{ ansible\_memtotal\_mb / 4|int }}

The result is ‘256.0’, same when I remove the |int and same when I do \* 0.25.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [July 24, 2014, 11:04am UTC](https://forum.ansible.com/t/calculate-from-facts/14570/5 "2014-07-24T11:04:31Z")

</div>

The precedence of the “|” is high in Jinja2. You’ll need some parenthesis.
